initial commit
This commit is contained in:
82
sdk/software/bsp/common.mk
Normal file
82
sdk/software/bsp/common.mk
Normal file
@@ -0,0 +1,82 @@
|
||||
|
||||
LA32R_GCC := loongarch32r-linux-gnusf-gcc
|
||||
LA32R_AS := loongarch32r-linux-gnusf-as
|
||||
LA32R_GXX := loongarch32r-linux-gnusf-g++
|
||||
LA32R_OBJDUMP := loongarch32r-linux-gnusf-objdump
|
||||
LA32R_GDB := loongarch32r-linux-gnusf-gdb
|
||||
LA32R_AR := loongarch32r-linux-gnusf-ar
|
||||
LA32R_OBJCOPY := loongarch32r-linux-gnusf-objcopy
|
||||
LA32R_READELF := loongarch32r-linux-gnusf-readelf
|
||||
|
||||
.PHONY: all
|
||||
all: $(TARGET)
|
||||
|
||||
#TODO: 根据Cache实际情况调整has_cache宏,以在start.S中生成正确的Cache初始化代码
|
||||
CFLAGS += -Dhas_cache=1
|
||||
CFLAGS += -Dcache_index_depth=0x100 -Dcache_offset_width=0x4 -Dcache_way=2
|
||||
CFLAGS += -ffunction-sections -fdata-sections
|
||||
CFLAGS += -nostartfiles -nostdlib -nostdinc -static -fno-builtin
|
||||
CFLAGS += -DCLOCKS_PER_SEC=CORE_CLOCKS_PER_SEC -D_CLOCKS_PER_SEC_=CORE_CLOCKS_PER_SEC
|
||||
CFLAGS += -DUSE_CPU_CLOCK_COUNT
|
||||
|
||||
#若使用 newlib , 将下面的 -lsemihost 替换为 -lgloss
|
||||
LDFLAGS += -T $(LINKER_SCRIPT) \
|
||||
-Wl,--gc-sections -Wl,--check-sections \
|
||||
-lc -lm -lg -lsemihost -lgcc -L$(PICOLIBC_DIR)/lib
|
||||
|
||||
LINKER_SCRIPT := $(COMMON_DIR)/env/script.lds
|
||||
|
||||
ASM_SRCS += $(COMMON_DIR)/env/start.S
|
||||
|
||||
ifeq ($(TARGET), RTThread_Nano)
|
||||
|
||||
else
|
||||
ASM_SRCS += $(COMMON_DIR)/env/trap_handler.S
|
||||
endif
|
||||
|
||||
C_SRCS += $(COMMON_DIR)/drivers/confreg_time.c
|
||||
C_SRCS += $(COMMON_DIR)/drivers/core_time.c
|
||||
C_SRCS += $(COMMON_DIR)/drivers/common_func.c
|
||||
C_SRCS += $(COMMON_DIR)/drivers/dvi.c \
|
||||
$(COMMON_DIR)/drivers/led.c \
|
||||
$(COMMON_DIR)/drivers/seg7.c
|
||||
|
||||
INCLUDES += -I./ \
|
||||
-I$(COMMON_DIR)/include \
|
||||
-I$(PICOLIBC_DIR)/include \
|
||||
-I$(GCC_DIR)/lib/gcc/loongarch32r-linux-gnusf/8.3.0/include \
|
||||
-I$(GCC_DIR)/lib/gcc/loongarch32r-linux-gnusf/8.3.0/include-fixed
|
||||
|
||||
ASM_OBJS := $(ASM_SRCS:.S=.o)
|
||||
C_OBJS := $(C_SRCS:.c=.o)
|
||||
|
||||
LINK_OBJS += $(ASM_OBJS) $(C_OBJS)
|
||||
LINK_DEPS += $(LINKER_SCRIPT)
|
||||
|
||||
CLEAN_OBJS += $(OBJDIR)/$(TARGET).elf $(LINK_OBJS) $(OBJDIR)/$(TARGET).s $(OBJDIR)/$(TARGET).bin $(OBJDIR)/convert $(OBJDIR)/axi_ram.coe $(OBJDIR)/axi_ram.mif $(OBJDIR)/rom.vlog
|
||||
|
||||
$(TARGET): $(LINK_OBJS) $(LINK_DEPS) convert Makefile
|
||||
$(LA32R_GCC) $(CFLAGS) $(INCLUDES) $(LINK_OBJS) -o $(OBJDIR)/$@.elf $(LDFLAGS)
|
||||
$(LA32R_OBJCOPY) -O binary $(OBJDIR)/$@.elf $(OBJDIR)/$@.bin
|
||||
$(LA32R_OBJDUMP) --disassemble-all -S $(OBJDIR)/$@.elf > $(OBJDIR)/$@.s
|
||||
$(OBJDIR)/convert $@.bin $(OBJDIR)/
|
||||
cp ./$(OBJDIR)/axi_ram.mif $(COMMON_DIR)/../../
|
||||
cp ./$(OBJDIR)/axi_ram.mif $(LA32RSOC_WINDOWS_HOME)/sdk
|
||||
cp ./$(OBJDIR)/$@.bin $(COMMON_DIR)/../../
|
||||
cp ./$(OBJDIR)/$@.bin $(LA32RSOC_WINDOWS_HOME)/sdk
|
||||
rm -f $(LINK_OBJS)
|
||||
rm -f $(OBJDIR)/convert
|
||||
|
||||
$(ASM_OBJS): %.o: %.S
|
||||
$(LA32R_GCC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
|
||||
|
||||
$(C_OBJS): %.o: %.c
|
||||
$(LA32R_GCC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
|
||||
|
||||
convert: $(COMMON_DIR)/env/convert.c
|
||||
mkdir -p $(OBJDIR)/
|
||||
gcc -o $(OBJDIR)/convert $(COMMON_DIR)/env/convert.c
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(CLEAN_OBJS)
|
||||
20
sdk/software/bsp/drivers/common_func.c
Normal file
20
sdk/software/bsp/drivers/common_func.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "common_func.h"
|
||||
|
||||
void RegWrite(unsigned int addr,unsigned int var)
|
||||
{
|
||||
*((volatile unsigned int *)(addr)) = var;
|
||||
}
|
||||
|
||||
unsigned int RegRead(unsigned int addr)
|
||||
{
|
||||
return (*((volatile unsigned int *)(addr)));
|
||||
}
|
||||
|
||||
//memcpy 32bit
|
||||
void SaveMemory(unsigned int *DestAddr, unsigned int *SrcAddr, unsigned int Size)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < Size; i += 1)
|
||||
*(U32*)(DestAddr + i) = SrcAddr[i];
|
||||
}
|
||||
|
||||
63
sdk/software/bsp/drivers/confreg_time.c
Normal file
63
sdk/software/bsp/drivers/confreg_time.c
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "confreg_time.h"
|
||||
#include "time.h"
|
||||
|
||||
unsigned long __attribute__((weak)) CONFREG_TIMER_BASE = 0xbf20f100;
|
||||
unsigned long __attribute__((weak)) CONFREG_CLOCKS_PER_SEC = 50000000L;
|
||||
unsigned long __attribute__((weak)) CORE_CLOCKS_PER_SEC = 33000000L;
|
||||
|
||||
unsigned long get_confreg_clock_count()
|
||||
{
|
||||
unsigned long contval;
|
||||
asm volatile(
|
||||
"la.local $r25, CONFREG_TIMER_BASE\n\t"
|
||||
"ld.w $r25, $r25, 0\n\t"
|
||||
"ld.w %0,$r25,0\n\t"
|
||||
:"=r"(contval)
|
||||
:
|
||||
:"$r25"
|
||||
);
|
||||
return contval;
|
||||
}
|
||||
|
||||
unsigned long get_cpu_clock_count()
|
||||
{
|
||||
unsigned long contval;
|
||||
asm volatile(
|
||||
"rdcntvl.w %0\n\t"
|
||||
:"=r"(contval)
|
||||
);
|
||||
return contval;
|
||||
}
|
||||
|
||||
unsigned long get_clock_count()
|
||||
{
|
||||
#ifdef USE_CPU_CLOCK_COUNT
|
||||
return get_cpu_clock_count();
|
||||
#else
|
||||
return get_confreg_clock_count();
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned long get_ns(void)
|
||||
{
|
||||
unsigned long n=0;
|
||||
n = get_clock_count();
|
||||
#ifdef USE_CPU_CLOCK_COUNT
|
||||
n=n*(NSEC_PER_USEC/(CORE_CLOCKS_PER_SEC/USEC_PER_SEC));
|
||||
#else
|
||||
n=n*(NSEC_PER_USEC/(CONFREG_CLOCKS_PER_SEC/USEC_PER_SEC));
|
||||
#endif
|
||||
return n;
|
||||
}
|
||||
|
||||
unsigned long get_us(void)
|
||||
{
|
||||
unsigned long n=0;
|
||||
n = get_clock_count();
|
||||
#ifdef USE_CPU_CLOCK_COUNT
|
||||
n=n/(CORE_CLOCKS_PER_SEC/USEC_PER_SEC);
|
||||
#else
|
||||
n=n/(CONFREG_CLOCKS_PER_SEC/USEC_PER_SEC);
|
||||
#endif
|
||||
return n;
|
||||
}
|
||||
30
sdk/software/bsp/drivers/core_time.c
Normal file
30
sdk/software/bsp/drivers/core_time.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "core_time.h"
|
||||
#include "confreg_time.h"
|
||||
|
||||
// default : 33 mhz
|
||||
|
||||
void delay_ms(uint32_t ms)
|
||||
{
|
||||
unsigned char overflow;
|
||||
unsigned long time,target_time,time_r,target_time_r;
|
||||
|
||||
time = get_cpu_clock_count();
|
||||
time_r = time;
|
||||
target_time = time + (CORE_CLOCKS_PER_SEC/1000)*ms;
|
||||
target_time_r = target_time;
|
||||
if( target_time < time){
|
||||
overflow = 1;
|
||||
target_time = 0xffffffff;
|
||||
}
|
||||
while(time < target_time){
|
||||
time = get_cpu_clock_count();
|
||||
if (time_r > time) break;
|
||||
time_r = time;
|
||||
}
|
||||
if (overflow) {
|
||||
while( time < target_time_r){
|
||||
time = get_cpu_clock_count();
|
||||
}
|
||||
overflow = 0;
|
||||
}
|
||||
}
|
||||
27
sdk/software/bsp/drivers/dvi.c
Normal file
27
sdk/software/bsp/drivers/dvi.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "dvi.h"
|
||||
|
||||
// 设置坐标和颜色的绘图函数
|
||||
void DVI_Draw_Rect(uint32_t x, uint32_t y, uint32_t l, uint32_t w)
|
||||
{
|
||||
// 创建坐标值,x 和 y 分别占用 12 位; width 和 height 用于定义范围
|
||||
uint32_t coordinates = ((x & 0xFFFF)<<16) | (y & 0xFFFF);
|
||||
|
||||
uint32_t size = ((l & 0xFFFF)<<16) | (w & 0xFFFF);
|
||||
|
||||
// 写入坐标和颜色寄存器
|
||||
RegWrite(DVI_RECT_DIR, coordinates);
|
||||
RegWrite(DVI_RECT_L_W, size);
|
||||
}
|
||||
|
||||
// 在指定位置绘制一个点的函数
|
||||
void DVI_Draw_SQU(uint32_t x, uint32_t y, uint32_t r)
|
||||
{
|
||||
// 创建坐标值,x 和 y 分别占用 12 位; width 和 height 用于定义范围
|
||||
uint32_t coordinates = ((x & 0xFFFF)<<16) | (y & 0xFFFF);
|
||||
|
||||
uint32_t size = ((r & 0xFFFF)<<16) | (r & 0xFFFF);
|
||||
|
||||
// 写入坐标和颜色寄存器
|
||||
RegWrite(DVI_SQU_DIR, coordinates);
|
||||
RegWrite(DVI_SQU_R, size);
|
||||
}
|
||||
28
sdk/software/bsp/drivers/led.c
Normal file
28
sdk/software/bsp/drivers/led.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "led.h"
|
||||
|
||||
// set leds pin
|
||||
void setLedPin(uint32_t data)
|
||||
{
|
||||
RegWrite(LEDS_GPIO_DATA,data);
|
||||
}
|
||||
|
||||
// toggle one led pin
|
||||
void toggleLedPin(uint32_t data)
|
||||
{
|
||||
uint32_t led_data;
|
||||
uint32_t process_bit;
|
||||
|
||||
led_data = RegRead(LEDS_GPIO_DATA);
|
||||
process_bit = 0x1 << data;
|
||||
|
||||
if(led_data & process_bit)
|
||||
{
|
||||
led_data = led_data & (~process_bit);
|
||||
}
|
||||
else
|
||||
{
|
||||
led_data = led_data | process_bit;
|
||||
}
|
||||
|
||||
RegWrite(LEDS_GPIO_DATA,led_data);
|
||||
}
|
||||
17
sdk/software/bsp/drivers/seg7.c
Normal file
17
sdk/software/bsp/drivers/seg7.c
Normal file
@@ -0,0 +1,17 @@
|
||||
// seg7.c
|
||||
|
||||
#include "seg7.h"
|
||||
|
||||
void setSegNum(uint32_t seg1,uint32_t num1,uint32_t seg2,uint32_t num2)
|
||||
{
|
||||
// select seg
|
||||
uint32_t select_seg = ((seg1<<2) + seg2);
|
||||
|
||||
RegWrite(SEG7_SELECT,select_seg);
|
||||
|
||||
// set num
|
||||
uint32_t num_seg = ((num1<<4) + num2);
|
||||
|
||||
RegWrite(SEG7_NUM,num_seg);
|
||||
|
||||
}
|
||||
103
sdk/software/bsp/env/convert.c
vendored
Normal file
103
sdk/software/bsp/env/convert.c
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void binary_out(FILE* out,unsigned char* mem)
|
||||
{
|
||||
char tmp;
|
||||
unsigned char num[8];
|
||||
int i;
|
||||
int j;
|
||||
|
||||
num[0] = 1;
|
||||
num[1] = 2;
|
||||
num[2] = 4;
|
||||
num[3] = 8;
|
||||
num[4] = 16;
|
||||
num[5] = 32;
|
||||
num[6] = 64;
|
||||
num[7] = 128;
|
||||
for(i=3;i>=0;i--)
|
||||
{
|
||||
for(j=7;j>=0;j--)
|
||||
{
|
||||
if( (mem[i] & num[j] ) != 0)
|
||||
tmp = '1';
|
||||
else
|
||||
tmp = '0';
|
||||
fprintf(out,"%c",tmp);
|
||||
}
|
||||
}
|
||||
fprintf(out,"\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
|
||||
if(argc < 3){
|
||||
fprintf(stderr, "Usage: convert main.bin directory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char str_bin[256];
|
||||
char str_coe[256], str_mif[256], str_vlog[256];
|
||||
strncpy(str_bin, argv[2], 256);
|
||||
strncpy(str_coe, argv[2], 256);
|
||||
strncpy(str_mif, argv[2], 256);
|
||||
strncpy(str_vlog,argv[2], 256);
|
||||
strncat(str_bin, argv[1], 255);
|
||||
strncat(str_coe, "axi_ram.coe", 255);
|
||||
strncat(str_mif, "axi_ram.mif", 255);
|
||||
strncat(str_vlog,"rom.vlog" , 255);
|
||||
//printf("%s\n%s\n%s\n%s\n%s\n%s\n", str_bin, str_data, str_inst_coe, str_inst_mif, str_data_coe, str_data_mif);
|
||||
|
||||
int i,j,k;
|
||||
unsigned char mem[32];
|
||||
|
||||
in = fopen(str_bin, "rb");
|
||||
out = fopen(str_coe,"w");
|
||||
|
||||
fprintf(out, "memory_initialization_radix = 16;\n");
|
||||
fprintf(out, "memory_initialization_vector =\n");
|
||||
while(!feof(in)) {
|
||||
if(fread(mem,1,4,in)!=4) {
|
||||
fprintf(out, "%02x%02x%02x%02x\n", mem[3], mem[2], mem[1], mem[0]);
|
||||
break;
|
||||
}
|
||||
fprintf(out, "%02x%02x%02x%02x\n", mem[3], mem[2], mem[1],mem[0]);
|
||||
}
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
in = fopen(str_bin, "rb");
|
||||
out = fopen(str_mif,"w");
|
||||
|
||||
while(!feof(in)) {
|
||||
if(fread(mem,1,4,in)!=4) {
|
||||
binary_out(out,mem);
|
||||
break;
|
||||
}
|
||||
binary_out(out,mem);
|
||||
}
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
in = fopen(str_bin, "rb");
|
||||
out = fopen(str_vlog,"w");
|
||||
|
||||
fprintf(out,"@1c000000\n");
|
||||
while(!feof(in)) {
|
||||
if (fread(mem,1,1,in) != 1) {
|
||||
fprintf(out,"%02x\n", mem[0]);
|
||||
break;
|
||||
}
|
||||
fprintf(out,"%02x\n", mem[0]);
|
||||
}
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
182
sdk/software/bsp/env/script.lds
vendored
Normal file
182
sdk/software/bsp/env/script.lds
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
OUTPUT_ARCH(loongarch)
|
||||
ENTRY(_start)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
isram (rwxai) : ORIGIN = 0x1c000000, LENGTH = 512K
|
||||
dsram (rwxai) : ORIGIN = 0x1c080000, LENGTH = 512K
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
__stack_size = DEFINED(__stack_size) ? __stack_size : 64K;
|
||||
.init :
|
||||
{
|
||||
KEEP (*(SORT_NONE(.init)))
|
||||
} >isram AT>isram
|
||||
.ilalign :
|
||||
{
|
||||
. = ALIGN(16);
|
||||
PROVIDE( _isram_lma = . );
|
||||
} >isram AT>isram
|
||||
.ialign :
|
||||
{
|
||||
PROVIDE( _isram = . );
|
||||
} >isram AT>isram
|
||||
.text :
|
||||
{
|
||||
_ftext = . ;
|
||||
*(.text.unlikely .text.unlikely.*)
|
||||
*(.text.startup .text.startup.*)
|
||||
*(.text .text.*)
|
||||
*(.gnu.linkonce.t.*)
|
||||
|
||||
/* section information for finsh shell */
|
||||
. = ALIGN(4);
|
||||
__fsymtab_start = .;
|
||||
KEEP(*(FSymTab))
|
||||
__fsymtab_end = .;
|
||||
|
||||
. = ALIGN(4);
|
||||
__vsymtab_start = .;
|
||||
KEEP(*(VSymTab))
|
||||
__vsymtab_end = .;
|
||||
|
||||
/* section information for utest */
|
||||
. = ALIGN(4);
|
||||
__rt_utest_tc_tab_start = .;
|
||||
KEEP(*(UtestTcTab))
|
||||
__rt_utest_tc_tab_end = .;
|
||||
|
||||
/* section information for at server */
|
||||
. = ALIGN(4);
|
||||
__rtatcmdtab_start = .;
|
||||
KEEP(*(RtAtCmdTab))
|
||||
__rtatcmdtab_end = .;
|
||||
. = ALIGN(4);
|
||||
|
||||
/* section information for initial. */
|
||||
. = ALIGN(4);
|
||||
__rt_init_start = .;
|
||||
KEEP(*(SORT(.rti_fn*)))
|
||||
__rt_init_end = .;
|
||||
|
||||
} >isram AT>isram
|
||||
.fini :
|
||||
{
|
||||
KEEP (*(SORT_NONE(.fini)))
|
||||
} >isram AT>isram
|
||||
. = ALIGN(16);
|
||||
PROVIDE (__etext = .);
|
||||
PROVIDE (_etext = .);
|
||||
PROVIDE (etext = .);
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
} >isram AT>isram
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
|
||||
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
} >isram AT>isram
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
|
||||
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
} >isram AT>isram
|
||||
.ctors :
|
||||
{
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*crtbegin?.o(.ctors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
} >isram AT>isram
|
||||
.dtors :
|
||||
{
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*crtbegin?.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
} >isram AT>isram
|
||||
|
||||
. = ALIGN(16);
|
||||
.ex_table_base :
|
||||
{
|
||||
_ex_table_base_start = .;
|
||||
. = 0x500;
|
||||
_ex_table_base_end = .;
|
||||
} >isram AT>isram
|
||||
|
||||
. = ALIGN(16);
|
||||
PROVIDE( _eisram = . );
|
||||
|
||||
.lalign :
|
||||
{
|
||||
. = ALIGN(16);
|
||||
PROVIDE( _data_lma = . );
|
||||
} >isram AT>isram
|
||||
.dalign :
|
||||
{
|
||||
. = ALIGN(16);
|
||||
PROVIDE( _data = . );
|
||||
} >dsram AT>isram
|
||||
.data :
|
||||
{
|
||||
*(.rdata)
|
||||
*(.rodata .rodata.*)
|
||||
rodata_end = .;
|
||||
*(.gnu.linkonce.r.*)
|
||||
*(.data .data.*)
|
||||
*(.gnu.linkonce.d.*)
|
||||
. = ALIGN(16);
|
||||
PROVIDE( __global_pointer$ = . + 0x800 );
|
||||
*(.sdata .sdata.*)
|
||||
*(.gnu.linkonce.s.*)
|
||||
. = ALIGN(16);
|
||||
*(.srodata.cst16)
|
||||
*(.srodata.cst8)
|
||||
*(.srodata.cst4)
|
||||
*(.srodata.cst2)
|
||||
*(.srodata .srodata.*)
|
||||
} >dsram AT>isram
|
||||
. = ALIGN(16);
|
||||
PROVIDE( _edata = . );
|
||||
PROVIDE( edata = . );
|
||||
PROVIDE( _fbss = . );
|
||||
.bss :
|
||||
{
|
||||
PROVIDE( __bss_start = . );
|
||||
*(.sbss*)
|
||||
*(.sbss.*)
|
||||
*(.dynsbss)
|
||||
*(.scommon)
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(.dynbss)
|
||||
*(.gnu.linkonce.sb.*)
|
||||
*(.bss .bss.*)
|
||||
*(.gnu.linkonce.b.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(16);
|
||||
} >dsram AT>dsram
|
||||
. = ALIGN(16);
|
||||
PROVIDE( _end = . );
|
||||
PROVIDE( end = . );
|
||||
PROVIDE (__heap_start = _end);
|
||||
.stack ORIGIN(dsram) + LENGTH(dsram) - __stack_size :
|
||||
{
|
||||
PROVIDE( _heap_end = . );
|
||||
PROVIDE (__heap_end = _heap_end);
|
||||
PROVIDE (__heap_size = __heap_end - __heap_start);
|
||||
. = __stack_size;
|
||||
PROVIDE( _stack = . );
|
||||
} >dsram AT>dsram
|
||||
}
|
||||
182
sdk/software/bsp/env/start.S
vendored
Normal file
182
sdk/software/bsp/env/start.S
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
#include "regdef.h"
|
||||
#include "uart_print.h"
|
||||
#include "handler.h"
|
||||
|
||||
.extern UART_BASE
|
||||
|
||||
.section .init
|
||||
.globl _start
|
||||
.type _start,@function
|
||||
|
||||
_start:
|
||||
|
||||
##init regs
|
||||
addi.w $r1,zero,0x0; addi.w $r2,zero,0x0; addi.w $r3,zero,0x0; addi.w $r4,zero,0x0;
|
||||
addi.w $r5,zero,0x0; addi.w $r6,zero,0x0; addi.w $r7,zero,0x0; addi.w $r8,zero,0x0;
|
||||
addi.w $r9,zero,0x0; addi.w $r10,zero,0x0; addi.w $r11,zero,0x0; addi.w $r12,zero,0x0;
|
||||
addi.w $r13,zero,0x0; addi.w $r14,zero,0x0; addi.w $r15,zero,0x0; addi.w $r16,zero,0x0;
|
||||
addi.w $r17,zero,0x0; addi.w $r18,zero,0x0; addi.w $r19,zero,0x0; addi.w $r20,zero,0x0;
|
||||
addi.w $r21,zero,0x0; addi.w $r22,zero,0x0; addi.w $r23,zero,0x0; addi.w $r24,zero,0x0;
|
||||
addi.w $r25,zero,0x0; addi.w $r26,zero,0x0; addi.w $r27,zero,0x0; addi.w $r28,zero,0x0;
|
||||
addi.w $r29,zero,0x0; addi.w $r30,zero,0x0; addi.w $r31,zero,0x0;
|
||||
|
||||
#if has_cache==1
|
||||
# invalid the old inst in icache and old data in dcache by index
|
||||
li.w t0,0x0
|
||||
#li.w t2,0x100
|
||||
li.w t2, cache_index_depth
|
||||
1:
|
||||
#slli.w t1, t0, 0x4
|
||||
slli.w t1, t0, cache_offset_width
|
||||
#if cache_way==1
|
||||
cacop 0x00, t1, 0x0
|
||||
cacop 0x01, t1, 0x0
|
||||
#elif cache_way==2
|
||||
cacop 0x00, t1, 0x0
|
||||
cacop 0x00, t1, 0x1
|
||||
cacop 0x01, t1, 0x0
|
||||
cacop 0x01, t1, 0x1
|
||||
#elif cache_way==4
|
||||
cacop 0x00, t1, 0x0
|
||||
cacop 0x00, t1, 0x1
|
||||
cacop 0x00, t1, 0x2
|
||||
cacop 0x00, t1, 0x3
|
||||
cacop 0x01, t1, 0x0
|
||||
cacop 0x01, t1, 0x1
|
||||
cacop 0x01, t1, 0x2
|
||||
cacop 0x01, t1, 0x3
|
||||
#endif
|
||||
addi.w t0, t0, 0x1
|
||||
bne t0, t2, 1b
|
||||
#else
|
||||
/* disable cache */
|
||||
li.w $r12,0x1
|
||||
csrwr $r12,0x101
|
||||
#endif
|
||||
|
||||
/* open da mode */
|
||||
li.w $r12,0x8
|
||||
li.w $r13,0x18
|
||||
csrxchg $r12,$r13,0x0
|
||||
|
||||
/* init dmw */
|
||||
csrwr $r0,0x180
|
||||
csrwr $r0,0x181
|
||||
li.w $r12,0x09
|
||||
csrwr $r12,0x180
|
||||
li.w $r12,0xa0000009
|
||||
csrwr $r12,0x181
|
||||
|
||||
/* open pg mode */
|
||||
li.w $r12,0x10
|
||||
li.w $r13,0x18
|
||||
csrxchg $r12,$r13,0x0
|
||||
|
||||
/* load data section */
|
||||
la.local t0, _data_lma
|
||||
la.local t1, _data
|
||||
la.local t2, _edata
|
||||
bgeu t1, t2, 2f
|
||||
1:
|
||||
ld.w t3, t0, 0
|
||||
st.w t3, t1, 0
|
||||
addi.w t0, t0, 4
|
||||
addi.w t1, t1, 4
|
||||
bltu t1, t2, 1b
|
||||
2:
|
||||
|
||||
/* clear bss section */
|
||||
la.local t0, __bss_start
|
||||
la.local t1, _end
|
||||
bgeu t0, t1, 2f
|
||||
1:
|
||||
st.w $r0, t0, 0
|
||||
addi.w t0, t0, 4
|
||||
bltu t0, t1, 1b
|
||||
2:
|
||||
|
||||
/* enable cache */
|
||||
#if has_cache==1
|
||||
li.w $r12,0x19
|
||||
csrwr $r12,0x180
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
/* init UART */
|
||||
la.local t0, UART_BASE
|
||||
ld.w t1, t0, 0
|
||||
#WRITE(li.wne,OFS_FIFO,FIFO_ENABLE|FIFO_RCV_RST|FIFO_XMT_RST|FIFO_TRIGGER_0);
|
||||
li.w t2, 0x07
|
||||
st.b t2, t1, 2
|
||||
#WRITE(li.wne,OFS_LINE_CONTROL, 0x80);
|
||||
li.w t2, 0x80
|
||||
st.b t2, t1, 3
|
||||
#WRITE(li.wne,OFS_DIVISOR_MSB, (divisor & 0xff00) >> 8);
|
||||
li.w t2, 0x00
|
||||
st.b t2, t1, 1
|
||||
#WRITE(li.wne,OFS_DIVISOR_LSB, divisor & 0xff);
|
||||
li.w t3, 0xbf20f500
|
||||
ld.w t3, t3, 0
|
||||
li.w t2, 0x1b
|
||||
beq zero, t3, 1f
|
||||
li.w t2, 0x1
|
||||
1:
|
||||
st.b t2, t1, 0
|
||||
#WRITE(li.wne,OFS_DATA_FORMAT, data | parity | stop);
|
||||
li.w t2, 0x3
|
||||
st.b t2, t1, 3
|
||||
#WRITE(li.wne,OFS_MODEM_CONTROL,0);
|
||||
li.w t2, 0x0
|
||||
st.b t2, t1, 4
|
||||
|
||||
/* init exception */
|
||||
#ifdef RTThread
|
||||
la.local t0, rtthread_irq_entry
|
||||
#else
|
||||
la.local t0, trap_handler
|
||||
#endif
|
||||
csrwr t0, csr_eentry
|
||||
|
||||
#clear int
|
||||
li.w t1, 0x1
|
||||
csrwr t1, csr_ticlr
|
||||
|
||||
#enable int
|
||||
li.w t1, 0x4
|
||||
#ifdef RTThread
|
||||
csrxchg zero, t1, csr_crmd
|
||||
#else
|
||||
csrxchg t1, t1, csr_crmd
|
||||
#endif
|
||||
csrwr zero, csr_prmd
|
||||
li.w t1, 0x1fff
|
||||
csrwr zero, csr_ecfg
|
||||
csrwr t1, csr_ecfg
|
||||
|
||||
|
||||
la.local sp, _stack
|
||||
|
||||
/* argc = argv = 0 */
|
||||
li.w a0, 0
|
||||
li.w a1, 0
|
||||
|
||||
#ifdef RTThread
|
||||
bl entry
|
||||
#else
|
||||
bl main
|
||||
#endif
|
||||
|
||||
/*tail exit*/
|
||||
bl _myexit
|
||||
1:
|
||||
b 1b
|
||||
|
||||
.globl _myexit
|
||||
.org 0x200
|
||||
_myexit:
|
||||
1:
|
||||
b 1b
|
||||
|
||||
|
||||
|
||||
188
sdk/software/bsp/env/trap_handler.S
vendored
Normal file
188
sdk/software/bsp/env/trap_handler.S
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
#include "regdef.h"
|
||||
|
||||
.macro TRAP_ENTRY_SETJMP
|
||||
addi.w sp, sp, -124
|
||||
|
||||
st.w ra, sp, 120
|
||||
st.w tp, sp, 116
|
||||
st.w sp, sp, 112
|
||||
st.w a0, sp, 108
|
||||
st.w a1, sp, 104
|
||||
st.w a2, sp, 100
|
||||
st.w a3, sp, 96
|
||||
st.w a4, sp, 92
|
||||
st.w a5, sp, 88
|
||||
st.w a6, sp, 84
|
||||
st.w a7, sp, 80
|
||||
st.w t0, sp, 76
|
||||
st.w t1, sp, 72
|
||||
st.w t2, sp, 68
|
||||
st.w t3, sp, 64
|
||||
st.w t4, sp, 60
|
||||
st.w t5, sp, 56
|
||||
st.w t6, sp, 52
|
||||
st.w t7, sp, 48
|
||||
st.w t8, sp, 44
|
||||
st.w $r21, sp,40
|
||||
st.w fp, sp, 36
|
||||
st.w s0, sp, 32
|
||||
st.w s1, sp, 28
|
||||
st.w s2, sp, 24
|
||||
st.w s3, sp, 20
|
||||
st.w s4, sp, 16
|
||||
st.w s5, sp, 12
|
||||
st.w s6, sp, 8
|
||||
st.w s7, sp, 4
|
||||
st.w s8, sp, 0
|
||||
|
||||
.endm
|
||||
|
||||
.macro TRAP_EXIT_LONGJMP
|
||||
|
||||
ld.w ra, sp, 120
|
||||
ld.w tp, sp, 116
|
||||
ld.w sp, sp, 112
|
||||
ld.w a0, sp, 108
|
||||
ld.w a1, sp, 104
|
||||
ld.w a2, sp, 100
|
||||
ld.w a3, sp, 96
|
||||
ld.w a4, sp, 92
|
||||
ld.w a5, sp, 88
|
||||
ld.w a6, sp, 84
|
||||
ld.w a7, sp, 80
|
||||
ld.w t0, sp, 76
|
||||
ld.w t1, sp, 72
|
||||
ld.w t2, sp, 68
|
||||
ld.w t3, sp, 64
|
||||
ld.w t4, sp, 60
|
||||
ld.w t5, sp, 56
|
||||
ld.w t6, sp, 52
|
||||
ld.w t7, sp, 48
|
||||
ld.w t8, sp, 44
|
||||
ld.w $r21, sp,40
|
||||
ld.w fp, sp, 36
|
||||
ld.w s0, sp, 32
|
||||
ld.w s1, sp, 28
|
||||
ld.w s2, sp, 24
|
||||
ld.w s3, sp, 20
|
||||
ld.w s4, sp, 16
|
||||
ld.w s5, sp, 12
|
||||
ld.w s6, sp, 8
|
||||
ld.w s7, sp, 4
|
||||
ld.w s8, sp, 0
|
||||
|
||||
addi.w sp, sp, 124
|
||||
|
||||
ertn
|
||||
|
||||
.endm
|
||||
|
||||
.section .text
|
||||
.align 6
|
||||
.global trap_handler
|
||||
.weak trap_handler
|
||||
trap_handler:
|
||||
|
||||
TRAP_ENTRY_SETJMP
|
||||
|
||||
csrrd a0, csr_estat
|
||||
csrrd a1, csr_era
|
||||
|
||||
srli.w t0, a0, 16
|
||||
bne zero, t0, is_exceptions
|
||||
andi t0, a0, 0x3FC
|
||||
srli.w t1, t0, 2
|
||||
|
||||
# 根据中断号跳转到相应的处理程序 priority
|
||||
move t2, t1
|
||||
andi t2, t2, 0x1
|
||||
li.w t8, 0x1
|
||||
beq t2, t8, handle_hwi0
|
||||
|
||||
move t2, t1
|
||||
andi t2, t2, 0x2
|
||||
li.w t8, 0x2
|
||||
beq t2, t8, handle_hwi1
|
||||
|
||||
move t2, t1
|
||||
andi t2, t2, 0x4
|
||||
li.w t8, 0x4
|
||||
beq t2, t8, handle_hwi2
|
||||
|
||||
move t2, t1
|
||||
andi t2, t2, 0x8
|
||||
li.w t8, 0x8
|
||||
beq t2, t8, handle_hwi3
|
||||
|
||||
move t2, t1
|
||||
andi t2, t2, 0x10
|
||||
li.w t8, 0x10
|
||||
beq t2, t8, handle_hwi4
|
||||
|
||||
move t2, t1
|
||||
andi t2, t2, 0x20
|
||||
li.w t8, 0x20
|
||||
beq t2, t8, handle_hwi5
|
||||
|
||||
move t2, t1
|
||||
andi t2, t2, 0x40
|
||||
li.w t8, 0x40
|
||||
beq t2, t8, handle_hwi6
|
||||
|
||||
move t2, t1
|
||||
andi t2, t2, 0x80
|
||||
li.w t8, 0x80
|
||||
beq t2, t8, handle_hwi7
|
||||
|
||||
b trap_jump_exit
|
||||
|
||||
is_exceptions:
|
||||
addi.w t8, a1, 4
|
||||
csrwr t8, csr_era
|
||||
1:
|
||||
b 1b
|
||||
|
||||
trap_jump_exit:
|
||||
TRAP_EXIT_LONGJMP
|
||||
|
||||
|
||||
# HWI0 处理程序
|
||||
handle_hwi0:
|
||||
|
||||
bl HWI0_IntrHandler
|
||||
|
||||
b trap_jump_exit
|
||||
|
||||
# HWI1 处理程序
|
||||
handle_hwi1:
|
||||
b trap_jump_exit
|
||||
|
||||
# HWI2 处理程序
|
||||
handle_hwi2:
|
||||
b trap_jump_exit
|
||||
|
||||
# HWI3 处理程序
|
||||
handle_hwi3:
|
||||
b trap_jump_exit
|
||||
|
||||
# HWI4 处理程序
|
||||
handle_hwi4:
|
||||
b trap_jump_exit
|
||||
|
||||
# HWI5 处理程序
|
||||
handle_hwi5:
|
||||
b trap_jump_exit
|
||||
|
||||
# HWI6 处理程序
|
||||
handle_hwi6:
|
||||
b trap_jump_exit
|
||||
|
||||
# HWI7 处理程序
|
||||
handle_hwi7:
|
||||
b trap_jump_exit
|
||||
|
||||
|
||||
.weak HWI0_IntrHandler
|
||||
HWI0_IntrHandler:
|
||||
1:
|
||||
b 1b
|
||||
99
sdk/software/bsp/include/common_func.h
Normal file
99
sdk/software/bsp/include/common_func.h
Normal file
@@ -0,0 +1,99 @@
|
||||
#ifndef common_func_H
|
||||
#define common_func_H
|
||||
|
||||
#include <larchintrin.h>
|
||||
|
||||
typedef signed int S32;
|
||||
typedef unsigned int U32;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef signed short S16;
|
||||
typedef unsigned short U16;
|
||||
typedef signed char S8;
|
||||
typedef unsigned char U8;
|
||||
typedef long long S64;
|
||||
typedef unsigned long long U64;
|
||||
|
||||
void RegWrite(unsigned int addr,unsigned int var);
|
||||
unsigned int RegRead(unsigned int addr);
|
||||
void SaveMemory(unsigned int *DestAddr, unsigned int *SrcAddr, unsigned int Size);
|
||||
|
||||
static inline U32 csr_readl(U32 reg)
|
||||
{
|
||||
return __csrrd_w(reg);
|
||||
}
|
||||
|
||||
static inline U64 csr_readq(U32 reg)
|
||||
{
|
||||
return __csrrd_w(reg);
|
||||
}
|
||||
|
||||
static inline void csr_writel(U32 val, U32 reg)
|
||||
{
|
||||
__csrwr_w(val, reg);
|
||||
}
|
||||
|
||||
static inline void csr_writeq(U64 val, U32 reg)
|
||||
{
|
||||
__csrwr_w(val, reg);
|
||||
}
|
||||
|
||||
static inline U32 csr_xchgl(U32 val, U32 mask, U32 reg)
|
||||
{
|
||||
return __csrxchg_w(val, mask, reg);
|
||||
}
|
||||
|
||||
static inline U64 csr_xchgq(U64 val, U64 mask, U32 reg)
|
||||
{
|
||||
return __csrxchg_w(val, mask, reg);
|
||||
}
|
||||
|
||||
#define CacheOp_Cache 0x03
|
||||
#define CacheOp_Op 0x1c
|
||||
|
||||
#define Cache_I 0x00
|
||||
#define Cache_D 0x01
|
||||
#define Cache_V 0x02
|
||||
#define Cache_S 0x03
|
||||
|
||||
#define Index_Invalidate 0x08
|
||||
#define Index_Writeback_Inv 0x08
|
||||
#define Hit_Invalidate 0x10
|
||||
#define Hit_Writeback_Inv 0x10
|
||||
|
||||
#define Index_Invalidate_I (Cache_I | Index_Invalidate)
|
||||
#define Index_Writeback_Inv_D (Cache_D | Index_Writeback_Inv)
|
||||
#define Hit_Invalidate_I (Cache_I | Hit_Invalidate)
|
||||
#define Hit_Writeback_Inv_D (Cache_D | Hit_Writeback_Inv)
|
||||
|
||||
#define cache_op(op, addr) \
|
||||
__asm__ __volatile__( \
|
||||
" cacop %0, %1 \n" \
|
||||
: \
|
||||
: "i" (op), "R" (*(unsigned char *)(addr)))
|
||||
|
||||
static inline void flush_icache_line_indexed(unsigned long addr)
|
||||
{
|
||||
cache_op(Index_Invalidate_I, addr);
|
||||
}
|
||||
|
||||
static inline void flush_dcache_line_indexed(unsigned long addr)
|
||||
{
|
||||
cache_op(Index_Writeback_Inv_D, addr);
|
||||
}
|
||||
|
||||
static inline void flush_icache_line(unsigned long addr)
|
||||
{
|
||||
cache_op(Hit_Invalidate_I, addr);
|
||||
}
|
||||
|
||||
static inline void flush_dcache_line(unsigned long addr)
|
||||
{
|
||||
cache_op(Hit_Writeback_Inv_D, addr);
|
||||
}
|
||||
|
||||
static inline void init_dcache_line(unsigned long addr)
|
||||
{
|
||||
cache_op(0x01, addr);
|
||||
}
|
||||
|
||||
#endif
|
||||
22
sdk/software/bsp/include/confreg_time.h
Normal file
22
sdk/software/bsp/include/confreg_time.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef _CONFREG_TIME_H_H
|
||||
#define _CONFREG_TIME_H_H
|
||||
|
||||
extern unsigned long CONFREG_TIMER_BASE;
|
||||
extern unsigned long CONFREG_CLOCKS_PER_SEC;
|
||||
extern unsigned long CORE_CLOCKS_PER_SEC;
|
||||
|
||||
#define MSEC_PER_SEC 1000L
|
||||
#define USEC_PER_MSEC 1000L
|
||||
#define NSEC_PER_USEC 1000L
|
||||
#define NSEC_PER_MSCEC 1000000L
|
||||
#define USEC_PER_SEC 1000000L
|
||||
#define NSEC_PER_SEC 1000000000L
|
||||
#define FSEC_PER_SEC 1000000000000000LL
|
||||
|
||||
unsigned long get_cpu_clock_count();//获取处理器核统计的时钟周期数
|
||||
unsigned long get_confreg_clock_count();//获取CONFREG的时钟周期数
|
||||
unsigned long get_clock_count();//根据是否存在宏 USE_CPU_CLOCK_COUNT 输出 处理器核/CONFREG 的计数器值
|
||||
unsigned long get_ns(void);//获取统计的纳秒数
|
||||
unsigned long get_us(void);//获取统计的微秒数
|
||||
|
||||
#endif
|
||||
8
sdk/software/bsp/include/core_time.h
Normal file
8
sdk/software/bsp/include/core_time.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef CORE_TIME_H
|
||||
#define CORE_TIME_H
|
||||
|
||||
#include "common_func.h"
|
||||
|
||||
void delay_ms(uint32_t ms);
|
||||
|
||||
#endif
|
||||
21
sdk/software/bsp/include/dvi.h
Normal file
21
sdk/software/bsp/include/dvi.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef DVI_H
|
||||
#define DVI_H
|
||||
#include "common_func.h"
|
||||
|
||||
#define DVI_BASEADDR 0xbf100000
|
||||
|
||||
#define DVI_RECT_DIR (DVI_BASEADDR + 0x0)
|
||||
|
||||
#define DVI_RECT_L_W (DVI_BASEADDR + 0x4)
|
||||
|
||||
#define DVI_SQU_DIR (DVI_BASEADDR + 0x8)
|
||||
|
||||
#define DVI_SQU_R (DVI_BASEADDR + 0xC)
|
||||
|
||||
// draw rect on DVI to x y
|
||||
void DVI_Draw_Rect(uint32_t x, uint32_t y, uint32_t l, uint32_t w);
|
||||
|
||||
// draw squ on DVI to x y r
|
||||
void DVI_Draw_SQU(uint32_t x, uint32_t y, uint32_t r);
|
||||
|
||||
#endif // DVI
|
||||
31
sdk/software/bsp/include/handler.h
Normal file
31
sdk/software/bsp/include/handler.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef _HANDLER_H
|
||||
#define _HANDLER_H
|
||||
|
||||
#define ex_tlb_load_present_type 0x1
|
||||
#define ex_tlb_store_present_type 0x2
|
||||
#define ex_tlb_fetch_present_type 0x3
|
||||
#define ex_tlb_modify_type 0x4
|
||||
#define ex_tlb_read_inhibit_type 0x5
|
||||
#define ex_tlb_execute_inhibit_type 0x6
|
||||
#define ex_tlb_privilege_error_type 0x7
|
||||
#define ex_ade_type 0x8
|
||||
#define ex_align_check_type 0x9
|
||||
#define ex_bound_check_error_type 0xa
|
||||
#define ex_syscall_type 0xb
|
||||
#define ex_break_type 0xc
|
||||
#define ex_ri_type 0xd
|
||||
#define ex_previlege_inst_type 0xe
|
||||
#define ex_fpe_disable_type 0xf
|
||||
#define ex_lsx_disable_type 0x10
|
||||
#define ex_lasx_disable_type 0x11
|
||||
#define ex_fpe_type 0x12
|
||||
#define ex_watch_type 0x13
|
||||
#define ex_bt_disable_type 0x14
|
||||
#define ex_bt_help_type 0x15
|
||||
#define ex_psi_type 0x16
|
||||
#define ex_hypcall_type 0x17
|
||||
#define ex_field_change_type 0x18
|
||||
#define ex_sate_related_type 0x19
|
||||
#define ex_tlb_refill 0x3f
|
||||
|
||||
#endif
|
||||
14
sdk/software/bsp/include/led.h
Normal file
14
sdk/software/bsp/include/led.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef LED_H
|
||||
#define LED_H
|
||||
|
||||
#include "common_func.h"
|
||||
|
||||
#define LEDS_BASEADDR 0xbf20f300
|
||||
|
||||
#define LEDS_GPIO_DATA (LEDS_BASEADDR + 0x00)
|
||||
|
||||
// set leds pin
|
||||
void setLedPin(uint32_t data);
|
||||
void toggleLedPin(uint32_t data);
|
||||
|
||||
#endif
|
||||
104
sdk/software/bsp/include/regdef.h
Normal file
104
sdk/software/bsp/include/regdef.h
Normal file
@@ -0,0 +1,104 @@
|
||||
#ifndef _SYS_REGDEF_H
|
||||
#define _SYS_REGDEF_H
|
||||
|
||||
# define zero $r0
|
||||
# define ra $r1
|
||||
# define tp $r2
|
||||
# define sp $r3
|
||||
# define a0 $r4
|
||||
# define a1 $r5
|
||||
# define a2 $r6
|
||||
# define a3 $r7
|
||||
# define a4 $r8
|
||||
# define a5 $r9
|
||||
# define a6 $r10
|
||||
# define a7 $r11
|
||||
# define v0 $r4
|
||||
# define v1 $r5
|
||||
# define t0 $r12
|
||||
# define t1 $r13
|
||||
# define t2 $r14
|
||||
# define t3 $r15
|
||||
# define t4 $r16
|
||||
# define t5 $r17
|
||||
# define t6 $r18
|
||||
# define t7 $r19
|
||||
# define t8 $r20
|
||||
# define x $r21
|
||||
# define fp $r22
|
||||
# define s0 $r23
|
||||
# define s1 $r24
|
||||
# define s2 $r25
|
||||
# define s3 $r26
|
||||
# define s4 $r27
|
||||
# define s5 $r28
|
||||
# define s6 $r29
|
||||
# define s7 $r30
|
||||
# define s8 $r31
|
||||
|
||||
# define fa0 $f0
|
||||
# define fa1 $f1
|
||||
# define fa2 $f2
|
||||
# define fa3 $f3
|
||||
# define fa4 $f4
|
||||
# define fa5 $f5
|
||||
# define fa6 $f6
|
||||
# define fa7 $f7
|
||||
# define fv0 $f0
|
||||
# define fv1 $f1
|
||||
# define ft0 $f8
|
||||
# define ft1 $f9
|
||||
# define ft2 $f10
|
||||
# define ft3 $f11
|
||||
# define ft4 $f12
|
||||
# define ft5 $f13
|
||||
# define ft6 $f14
|
||||
# define ft7 $f15
|
||||
# define ft8 $f16
|
||||
# define ft9 $f17
|
||||
# define ft10 $f18
|
||||
# define ft11 $f19
|
||||
# define ft12 $f20
|
||||
# define ft13 $f21
|
||||
# define ft14 $f22
|
||||
# define ft15 $f23
|
||||
# define fs0 $f24
|
||||
# define fs1 $f25
|
||||
# define fs2 $f26
|
||||
# define fs3 $f27
|
||||
# define fs4 $f28
|
||||
# define fs5 $f29
|
||||
# define fs6 $f30
|
||||
# define fs7 $f31
|
||||
|
||||
#define csr_crmd 0x0
|
||||
#define csr_prmd 0x1
|
||||
#define csr_euen 0x2
|
||||
#define csr_ecfg 0x4
|
||||
#define csr_estat 0x5
|
||||
#define csr_era 0x6
|
||||
#define csr_badv 0x7
|
||||
#define csr_eentry 0xc
|
||||
#define csr_tlbidx 0x10
|
||||
#define csr_tlbehi 0x11
|
||||
#define csr_tlbelo0 0x12
|
||||
#define csr_tlbelo1 0x13
|
||||
#define csr_asid 0x18
|
||||
#define csr_pgdl 0x19
|
||||
#define csr_pgdh 0x1a
|
||||
#define csr_pgd 0x1b
|
||||
#define csr_cpuid 0x20
|
||||
#define csr_save0 0x30
|
||||
#define csr_save1 0x31
|
||||
#define csr_save2 0x32
|
||||
#define csr_save3 0x33
|
||||
#define csr_tid 0x40
|
||||
#define csr_tcfg 0x41
|
||||
#define csr_tval 0x42
|
||||
#define csr_ticlr 0x44
|
||||
#define csr_llbctl 0x60
|
||||
#define csr_tlbrentry 0x88
|
||||
#define csr_dmw0 0x180
|
||||
#define csr_dmw1 0x181
|
||||
|
||||
#endif
|
||||
17
sdk/software/bsp/include/seg7.h
Normal file
17
sdk/software/bsp/include/seg7.h
Normal file
@@ -0,0 +1,17 @@
|
||||
// seg7.h
|
||||
|
||||
#ifndef SEG7_H
|
||||
#define SEG7_H
|
||||
|
||||
#include "common_func.h"
|
||||
|
||||
#define SEG7_BASEADDR 0xbf20f200
|
||||
|
||||
#define SEG7_SELECT (SEG7_BASEADDR + 0x00)
|
||||
|
||||
#define SEG7_NUM (SEG7_BASEADDR + 0x04)
|
||||
|
||||
// set seg num
|
||||
void setSegNum(uint32_t seg1,uint32_t num1,uint32_t seg2,uint32_t num2);
|
||||
|
||||
#endif
|
||||
12
sdk/software/bsp/include/uart_print.h
Normal file
12
sdk/software/bsp/include/uart_print.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _UART_PRINT_H
|
||||
#define _UART_PRINT_H
|
||||
|
||||
#define UART_PRINT(str)\
|
||||
la a0, 1f;\
|
||||
.section .rodata ;\
|
||||
1: ;\
|
||||
.asciz str ;\
|
||||
.section .init ;\
|
||||
bl %plt(puts)
|
||||
|
||||
#endif
|
||||
14
sdk/software/examples/c_prg/inner_product/Makefile
Normal file
14
sdk/software/examples/c_prg/inner_product/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
TARGET = inner_product
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../../bsp
|
||||
GCC_DIR=../../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../../toolchains/picolibc
|
||||
include ../../../bsp/common.mk
|
||||
446
sdk/software/examples/c_prg/inner_product/inner_product.c
Normal file
446
sdk/software/examples/c_prg/inner_product/inner_product.c
Normal file
@@ -0,0 +1,446 @@
|
||||
/*
|
||||
Copyright 2008 Adobe Systems Incorporated
|
||||
Copyright 2018-2019 Chris Cox
|
||||
Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
|
||||
or a copy at http://stlab.adobe.com/licenses.html )
|
||||
|
||||
|
||||
Goal: Test performance of various idioms for calculating the inner product of two sequences.
|
||||
|
||||
NOTE: Inner products are common in mathematical and geometry processing applications,
|
||||
plus some audio and image processing.
|
||||
|
||||
|
||||
Assumptions:
|
||||
1) The compiler will optimize inner product operations.
|
||||
|
||||
2) The compiler may recognize ineffecient inner product idioms
|
||||
and substitute efficient methods when it can.
|
||||
NOTE: the best method is highly dependent on the data types and CPU architecture
|
||||
|
||||
3) std::inner_product will be well optimized for all types and containers.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbfe001e0; //UART16550的虚地址
|
||||
unsigned long CONFREG_UART_BASE = 0xbfafff10; //CONFREG模拟UART的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbfafe000; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 100000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
clock_t start_time, end_time;
|
||||
|
||||
// this constant may need to be adjusted to give reasonable minimum times
|
||||
// For best results, times should be about 1.0 seconds for the minimum test run
|
||||
int iterations = 5;
|
||||
|
||||
|
||||
// 8000 items, or between 8 and 64k of data
|
||||
// this is intended to remain within the L2 cache of most common CPUs
|
||||
const int SIZE = 8000;
|
||||
|
||||
|
||||
// initial value for filling our arrays, may be changed from the command line
|
||||
int32_t init_value_8 = 3;
|
||||
int32_t init_value_16 = 211;
|
||||
int32_t init_value_32 = 1065;
|
||||
float init_value_f16 = 5.0;
|
||||
double init_value_f32 = 365.0;
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
void fill_8(int8_t * first, int8_t * last, int8_t value) {
|
||||
while (first != last) *first++ = (int8_t)(value);
|
||||
}
|
||||
|
||||
void fill_u8(uint8_t * first, uint8_t * last, uint8_t value) {
|
||||
while (first != last) *first++ = (uint8_t)(value);
|
||||
}
|
||||
|
||||
void fill_16(int16_t * first, int16_t * last, int16_t value) {
|
||||
while (first != last) *first++ = (int16_t)(value);
|
||||
}
|
||||
|
||||
void fill_u16(uint16_t * first, uint16_t * last, uint16_t value) {
|
||||
while (first != last) *first++ = (uint16_t)(value);
|
||||
}
|
||||
|
||||
void fill_32(int32_t * first, int32_t * last, int32_t value) {
|
||||
while (first != last) *first++ = (int32_t)(value);
|
||||
}
|
||||
|
||||
void fill_u32(uint32_t * first, uint32_t * last, uint32_t value) {
|
||||
while (first != last) *first++ = (uint32_t)(value);
|
||||
}
|
||||
|
||||
void fill_f16(float * first, float * last, float value) {
|
||||
while (first != last) *first++ = (float)(value);
|
||||
}
|
||||
|
||||
void fill_f32(double * first, double * last, double value) {
|
||||
while (first != last) *first++ = (double)(value);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
// a trivial for loop
|
||||
|
||||
void test_inner_product_8( const int8_t* first, const int8_t* second, const size_t count, const char *label) {
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(int i = 0; i < iterations; ++i) {
|
||||
|
||||
int8_t sum = 0 ;
|
||||
for (size_t j = 0; j < count; ++j) {
|
||||
sum += first[j] * second[j];
|
||||
}
|
||||
|
||||
//check_sum( sum, label );
|
||||
int8_t target = (int8_t)(init_value_8)*(int8_t)(init_value_8)*SIZE;
|
||||
if ( abs( sum - target ) > (int8_t)(1.0e-6) )
|
||||
printf("test %s failed\n", label);
|
||||
}
|
||||
|
||||
// need the labels to remain valid until we print the summary
|
||||
end_time = clock();
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
printf("CLOCKS_PER_SEC=%d\n",CLOCKS_PER_SEC);
|
||||
printf("\"%s, %lu items\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
}
|
||||
|
||||
void test_inner_product_u8( const uint8_t* first, const uint8_t* second, const size_t count, const char *label) {
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(int i = 0; i < iterations; ++i) {
|
||||
|
||||
uint8_t sum = 0 ;
|
||||
for (size_t j = 0; j < count; ++j) {
|
||||
sum += first[j] * second[j];
|
||||
}
|
||||
|
||||
//check_sum( sum, label );
|
||||
uint8_t target = (uint8_t)(init_value_8)*(uint8_t)(init_value_8)*SIZE;
|
||||
if ( ( sum - target ) > (uint8_t)(1.0e-6) )
|
||||
printf("test %s failed\n", label);
|
||||
}
|
||||
|
||||
// need the labels to remain valid until we print the summary
|
||||
end_time = clock();
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
printf("\"%s, %lu items\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
}
|
||||
|
||||
void test_inner_product_16( const int16_t* first, const int16_t* second, const size_t count, const char *label) {
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(int i = 0; i < iterations; ++i) {
|
||||
|
||||
int16_t sum = 0 ;
|
||||
for (size_t j = 0; j < count; ++j) {
|
||||
sum += first[j] * second[j];
|
||||
}
|
||||
|
||||
//check_sum( sum, label );
|
||||
int16_t target = (int16_t)(init_value_16)*(int16_t)(init_value_16)*SIZE;
|
||||
if ( abs( sum - target ) > (int16_t)(1.0e-6) )
|
||||
printf("test %s failed\n", label);
|
||||
}
|
||||
|
||||
// need the labels to remain valid until we print the summary
|
||||
end_time = clock();
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
printf("\"%s, %lu items\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
}
|
||||
|
||||
void test_inner_product_u16( const uint16_t* first, const uint16_t* second, const size_t count, const char *label) {
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(int i = 0; i < iterations; ++i) {
|
||||
|
||||
uint16_t sum = 0 ;
|
||||
for (size_t j = 0; j < count; ++j) {
|
||||
sum += first[j] * second[j];
|
||||
}
|
||||
|
||||
//check_sum( sum, label );
|
||||
uint16_t target = (uint16_t)(init_value_16)*(uint16_t)(init_value_16)*SIZE;
|
||||
if ( ( sum - target ) > (uint16_t)(1.0e-6) )
|
||||
printf("test %s failed\n", label);
|
||||
}
|
||||
|
||||
// need the labels to remain valid until we print the summary
|
||||
end_time = clock();
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
printf("\"%s, %lu items\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
}
|
||||
|
||||
void test_inner_product_32( const int32_t* first, const int32_t* second, const size_t count, const char *label) {
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(int i = 0; i < iterations; ++i) {
|
||||
|
||||
int32_t sum = 0 ;
|
||||
for (size_t j = 0; j < count; ++j) {
|
||||
sum += first[j] * second[j];
|
||||
}
|
||||
|
||||
//check_sum( sum, label );
|
||||
int32_t target = (int32_t)(init_value_32)*(int32_t)(init_value_32)*SIZE;
|
||||
if ( abs( sum - target ) > (int32_t)(1.0e-6) )
|
||||
printf("test %s failed\n", label);
|
||||
}
|
||||
|
||||
// need the labels to remain valid until we print the summary
|
||||
end_time = clock();
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
printf("\"%s, %lu items\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
}
|
||||
|
||||
void test_inner_product_u32( const uint32_t* first, const uint32_t* second, const size_t count, const char *label) {
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(int i = 0; i < iterations; ++i) {
|
||||
|
||||
uint32_t sum = 0 ;
|
||||
for (size_t j = 0; j < count; ++j) {
|
||||
sum += first[j] * second[j];
|
||||
}
|
||||
|
||||
//check_sum( sum, label );
|
||||
uint32_t target = (uint32_t)(init_value_32)*(uint32_t)(init_value_32)*SIZE;
|
||||
if ( ( sum - target ) > (uint32_t)(1.0e-6) )
|
||||
printf("test %s failed\n", label);
|
||||
}
|
||||
|
||||
// need the labels to remain valid until we print the summary
|
||||
end_time = clock();
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
printf("\"%s, %lu items\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
}
|
||||
|
||||
void test_inner_product_f16( const float* first, const float* second, const size_t count, const char *label) {
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(int i = 0; i < iterations; ++i) {
|
||||
|
||||
float sum = 0 ;
|
||||
for (size_t j = 0; j < count; ++j) {
|
||||
sum += first[j] * second[j];
|
||||
}
|
||||
|
||||
//check_sum( sum, label );
|
||||
float target = (float)(init_value_f16)*(float)(init_value_f16)*SIZE;
|
||||
if ( fabs( sum - target ) > (float)(1.0e-6) )
|
||||
printf("test %s failed\n", label);
|
||||
}
|
||||
|
||||
// need the labels to remain valid until we print the summary
|
||||
end_time = clock();
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
printf("\"%s, %lu items\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
}
|
||||
|
||||
void test_inner_product_f32( const double* first, const double* second, const size_t count, const char *label) {
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(int i = 0; i < iterations; ++i) {
|
||||
|
||||
double sum = 0 ;
|
||||
for (size_t j = 0; j < count; ++j) {
|
||||
sum += first[j] * second[j];
|
||||
}
|
||||
|
||||
//check_sum( sum, label );
|
||||
double target = (double)(init_value_f32)*(double)(init_value_f32)*SIZE;
|
||||
if ( fabs( sum - target ) > (double)(1.0e-6) )
|
||||
printf("test %s failed\n", label);
|
||||
}
|
||||
|
||||
// need the labels to remain valid until we print the summary
|
||||
end_time = clock();
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
printf("\"%s, %lu items\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
// NOTE - can't make generic template template argument without C++17
|
||||
// I would like to have TestOneFunction to handle all the types and if's, but need to use different types with it inside
|
||||
// see sum_sequence.cpp
|
||||
|
||||
|
||||
void TestOneType_8()
|
||||
{
|
||||
int8_t data[SIZE];
|
||||
int8_t dataB[SIZE];
|
||||
|
||||
fill_8(data, data+SIZE, (int8_t)(init_value_8));
|
||||
fill_8(dataB, dataB+SIZE, (int8_t)(init_value_8));
|
||||
|
||||
test_inner_product_8( data, dataB, SIZE, "int_8 inner_product1 to int_8");
|
||||
}
|
||||
|
||||
void TestOneType_u8()
|
||||
{
|
||||
uint8_t data[SIZE];
|
||||
uint8_t dataB[SIZE];
|
||||
|
||||
fill_u8(data, data+SIZE, (uint8_t)(init_value_8));
|
||||
fill_u8(dataB, dataB+SIZE, (uint8_t)(init_value_8));
|
||||
|
||||
test_inner_product_u8( data, dataB, SIZE, "uint_8 inner_product1 to uint_8");
|
||||
}
|
||||
|
||||
|
||||
void TestOneType_16()
|
||||
{
|
||||
int16_t data[SIZE];
|
||||
int16_t dataB[SIZE];
|
||||
|
||||
fill_16(data, data+SIZE, (int16_t)(init_value_16));
|
||||
fill_16(dataB, dataB+SIZE, (int16_t)(init_value_16));
|
||||
|
||||
test_inner_product_16( data, dataB, SIZE, "int_16 inner_product1 to int_16");
|
||||
}
|
||||
|
||||
void TestOneType_u16()
|
||||
{
|
||||
uint16_t data[SIZE];
|
||||
uint16_t dataB[SIZE];
|
||||
|
||||
fill_u16(data, data+SIZE, (uint16_t)(init_value_16));
|
||||
fill_u16(dataB, dataB+SIZE, (uint16_t)(init_value_16));
|
||||
|
||||
test_inner_product_u16( data, dataB, SIZE, "uint_16 inner_product1 to uint_16");
|
||||
}
|
||||
|
||||
void TestOneType_32()
|
||||
{
|
||||
int32_t data[SIZE];
|
||||
int32_t dataB[SIZE];
|
||||
|
||||
fill_32(data, data+SIZE, (int32_t)(init_value_32));
|
||||
fill_32(dataB, dataB+SIZE, (int32_t)(init_value_32));
|
||||
|
||||
test_inner_product_32( data, dataB, SIZE, "int_32 inner_product1 to int_32");
|
||||
}
|
||||
|
||||
void TestOneType_u32()
|
||||
{
|
||||
uint32_t data[SIZE];
|
||||
uint32_t dataB[SIZE];
|
||||
|
||||
fill_u32(data, data+SIZE, (uint32_t)(init_value_32));
|
||||
fill_u32(dataB, dataB+SIZE, (uint32_t)(init_value_32));
|
||||
|
||||
test_inner_product_u32( data, dataB, SIZE, "uint_32 inner_product1 to uint_32");
|
||||
}
|
||||
|
||||
void TestOneType_f16()
|
||||
{
|
||||
float data[SIZE];
|
||||
float dataB[SIZE];
|
||||
|
||||
fill_f16(data, data+SIZE, (float)(init_value_f16));
|
||||
fill_f16(dataB, dataB+SIZE, (float)(init_value_f16));
|
||||
|
||||
test_inner_product_f16( data, dataB, SIZE, "float inner_product1 to float");
|
||||
}
|
||||
|
||||
void TestOneType_f32()
|
||||
{
|
||||
double data[SIZE];
|
||||
double dataB[SIZE];
|
||||
|
||||
fill_f32(data, data+SIZE, (double)(init_value_f32));
|
||||
fill_f32(dataB, dataB+SIZE, (double)(init_value_f32));
|
||||
|
||||
test_inner_product_f32( data, dataB, SIZE, "double inner_product1 to double");
|
||||
}
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
// output command for documentation:
|
||||
int i;
|
||||
// for (i = 0; i < argc; ++i)
|
||||
// printf("%s ", argv[i] );
|
||||
// printf("\n");
|
||||
|
||||
if (argc > 1) iterations = atoi(argv[1]);
|
||||
// if (argc > 2) init_value = (int32_t) atoi(argv[2]);
|
||||
|
||||
|
||||
TestOneType_8();
|
||||
TestOneType_u8();
|
||||
TestOneType_16();
|
||||
TestOneType_u16();
|
||||
TestOneType_32();
|
||||
TestOneType_u32();
|
||||
|
||||
TestOneType_f16();
|
||||
TestOneType_f32();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// the end
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
14
sdk/software/examples/c_prg/lookup_table/Makefile
Normal file
14
sdk/software/examples/c_prg/lookup_table/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
TARGET = lookup_table
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../../bsp
|
||||
GCC_DIR=../../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../../toolchains/picolibc
|
||||
include ../../../bsp/common.mk
|
||||
315
sdk/software/examples/c_prg/lookup_table/lookup_table.c
Normal file
315
sdk/software/examples/c_prg/lookup_table/lookup_table.c
Normal file
@@ -0,0 +1,315 @@
|
||||
/*
|
||||
Copyright 2008-2009 Adobe Systems Incorporated
|
||||
Copyright 2018 Chris Cox
|
||||
Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
|
||||
or a copy at http://stlab.adobe.com/licenses.html )
|
||||
|
||||
|
||||
Goal: Test performance of various idioms and optimizations for lookup tables.
|
||||
|
||||
|
||||
Assumptions:
|
||||
1) The compiler will optimize lookup table operations.
|
||||
Unrolling will usually be needed to hide read latencies.
|
||||
|
||||
2) The compiler should recognize ineffecient lookup table idioms and substitute efficient methods.
|
||||
Many different CPU architecture issues will require reading and writing words for best performance.
|
||||
CPUs with...
|
||||
cache write-back/write-combine delays.
|
||||
store forwarding delays.
|
||||
slow cache access relative to shifts/masks.
|
||||
slow partial word (byte) access.
|
||||
fast shift/mask operations.
|
||||
On some CPUs, a lookup can be handled with vector instructions.
|
||||
On some CPUs, special cache handling is needed (especially 2way caches).
|
||||
|
||||
|
||||
|
||||
|
||||
TODO - lookup and interpolate (int16_t, int32_t, int64_t, float, double)
|
||||
TODO - 2D and 3D LUTs, simple and interpolated
|
||||
|
||||
*/
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbfe001e0; //UART16550的虚地址
|
||||
unsigned long CONFREG_UART_BASE = 0xbfafff10; //CONFREG模拟UART的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbfafe000; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 100000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
clock_t start_time, end_time;
|
||||
|
||||
// this constant may need to be adjusted to give reasonable minimum times
|
||||
// For best results, times should be about 1.0 seconds for the minimum test run
|
||||
int base_iterations = 1;
|
||||
int iterations = 1;
|
||||
|
||||
// 4000 items, or about 2..4k of data
|
||||
// this is intended to remain within the L1 cache of most common CPUs
|
||||
#define SIZE_SMALL 2000
|
||||
|
||||
// about 0.5..1M of data
|
||||
// 没有那么大内存,这里给50KB到100KB
|
||||
// this is intended to be outside the L2 cache of most common CPUs
|
||||
#define SIZE 50000
|
||||
|
||||
// initial value for filling our arrays, may be changed from the command line
|
||||
int32_t init_value = 3;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// our global arrays of numbers
|
||||
|
||||
uint8_t inputData8[SIZE];
|
||||
uint8_t resultData8[SIZE];
|
||||
|
||||
uint16_t inputData16[SIZE];
|
||||
uint16_t resultData16[SIZE];
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
|
||||
void fill_8(uint8_t * first, uint8_t * last, uint8_t value) {
|
||||
while (first != last) *first++ = (uint8_t)(value);
|
||||
}
|
||||
|
||||
void fill_16(uint16_t * first, uint16_t * last, uint16_t value) {
|
||||
while (first != last) *first++ = (uint16_t)(value);
|
||||
}
|
||||
|
||||
void fill_random_8(uint8_t * first, uint8_t * last) {
|
||||
srand((unsigned int)init_value + 123 );
|
||||
while (first != last) {
|
||||
*first++ = (uint8_t)rand();
|
||||
}
|
||||
}
|
||||
|
||||
void fill_random_16(uint16_t * first, uint16_t * last) {
|
||||
srand((unsigned int)init_value + 123 );
|
||||
while (first != last) {
|
||||
*first++ = (uint16_t)rand();
|
||||
}
|
||||
}
|
||||
|
||||
int max(int a, int b){
|
||||
if(a > b)
|
||||
return a;
|
||||
else
|
||||
return b;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
|
||||
|
||||
// baseline - a trivial loop
|
||||
|
||||
void test_lut1_u8(const uint8_t* input, uint8_t *result, const int count, const uint8_t* LUT, const char *label) {
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(int i = 0; i < iterations; ++i) {
|
||||
for (int j = 0; j < count; ++j) {
|
||||
result[j] = LUT[ input[j] ];
|
||||
}
|
||||
}
|
||||
|
||||
end_time = clock();
|
||||
|
||||
int j;
|
||||
|
||||
for (j = 0; j < count; ++j) {
|
||||
if (result[j] != (uint8_t)(init_value)) {
|
||||
printf("test %s failed (got %u, expected %u)\n", label, (unsigned)(result[j]), (unsigned)(init_value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
printf("\"%s, %d times\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
|
||||
}
|
||||
|
||||
void test_lut1_8(const int8_t* input, int8_t *result, const int count, const int8_t* LUT, const char *label) {
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(int i = 0; i < iterations; ++i) {
|
||||
for (int j = 0; j < count; ++j) {
|
||||
result[j] = LUT[ input[j] ];
|
||||
}
|
||||
}
|
||||
|
||||
end_time = clock();
|
||||
|
||||
int j;
|
||||
|
||||
for (j = 0; j < count; ++j) {
|
||||
if (result[j] != (int8_t)(init_value)) {
|
||||
printf("test %s failed (got %u, expected %u)\n", label, (unsigned)(result[j]), (unsigned)(init_value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
printf("\"%s, %d times\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
|
||||
}
|
||||
|
||||
void test_lut1_u16(const uint16_t* input, uint16_t *result, const int count, const uint16_t* LUT, const char *label) {
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(int i = 0; i < iterations; ++i) {
|
||||
for (int j = 0; j < count; ++j) {
|
||||
result[j] = LUT[ input[j] ];
|
||||
}
|
||||
}
|
||||
|
||||
end_time = clock();
|
||||
|
||||
int j;
|
||||
|
||||
for (j = 0; j < count; ++j) {
|
||||
if (result[j] != (uint16_t)(init_value)) {
|
||||
printf("test %s failed (got %u, expected %u)\n", label, (unsigned)(result[j]), (unsigned)(init_value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
printf("\"%s, %d times\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
|
||||
}
|
||||
|
||||
void test_lut1_16(const int16_t* input, int16_t *result, const int count, const int16_t* LUT, const char *label) {
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(int i = 0; i < iterations; ++i) {
|
||||
for (int j = 0; j < count; ++j) {
|
||||
result[j] = LUT[ input[j] ];
|
||||
}
|
||||
}
|
||||
|
||||
end_time = clock();
|
||||
|
||||
int j;
|
||||
|
||||
for (j = 0; j < count; ++j) {
|
||||
if (result[j] != (int16_t)(init_value)) {
|
||||
printf("test %s failed (got %u, expected %u)\n", label, (unsigned)(result[j]), (unsigned)(init_value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
printf("\"%s, %d times\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
// output command for documentation:
|
||||
int i;
|
||||
// for (i = 0; i < argc; ++i)
|
||||
// printf("%s ", argv[i] );
|
||||
// printf("\n");
|
||||
|
||||
if (argc > 1) base_iterations = atoi(argv[1]);
|
||||
if (argc > 2) init_value = (int32_t) atoi(argv[2]);
|
||||
|
||||
uint8_t myLUT8[ 256 ];
|
||||
uint16_t myLUT16[ 65536 ];
|
||||
|
||||
|
||||
fill_8(myLUT8, myLUT8+256, (uint8_t)(init_value));
|
||||
fill_16(myLUT16, myLUT16+65536, (uint16_t)(init_value));
|
||||
|
||||
fill_random_8( inputData8, inputData8+SIZE );
|
||||
fill_random_16( inputData16, inputData16+SIZE );
|
||||
|
||||
|
||||
// uint8_t
|
||||
iterations = base_iterations;
|
||||
|
||||
test_lut1_u8( inputData8, inputData8, SIZE_SMALL, myLUT8, "uint8_t lookup table1 small inplace");
|
||||
test_lut1_u8( inputData8, resultData8, SIZE_SMALL, myLUT8, "uint8_t lookup table1 small");
|
||||
|
||||
iterations = max( 1, (int)(((uint64_t)base_iterations * SIZE_SMALL) / SIZE) );
|
||||
|
||||
test_lut1_u8( inputData8, inputData8, SIZE, myLUT8, "uint8_t lookup table1 large inplace");
|
||||
test_lut1_u8( inputData8, resultData8, SIZE, myLUT8, "uint8_t lookup table1 large");
|
||||
|
||||
|
||||
|
||||
// int8_t
|
||||
iterations = base_iterations;
|
||||
|
||||
test_lut1_8( (int8_t*)inputData8, (int8_t*)inputData8, SIZE_SMALL, (int8_t*)(myLUT8+128), "int8_t lookup table1 small inplace");
|
||||
test_lut1_8( (int8_t*)inputData8, (int8_t*)resultData8, SIZE_SMALL, (int8_t*)(myLUT8+128), "int8_t lookup table1 small");
|
||||
|
||||
iterations = max( 1, (int)(((uint64_t)base_iterations * SIZE_SMALL) / SIZE) );
|
||||
|
||||
test_lut1_8( (int8_t*)inputData8, (int8_t*)inputData8, SIZE, (int8_t*)(myLUT8+128), "int8_t lookup table1 large inplace");
|
||||
test_lut1_8( (int8_t*)inputData8, (int8_t*)resultData8, SIZE, (int8_t*)(myLUT8+128), "int8_t lookup table1 large");
|
||||
|
||||
|
||||
// uint16_t
|
||||
iterations = base_iterations;
|
||||
|
||||
test_lut1_u16( inputData16, inputData16, SIZE_SMALL, myLUT16, "uint16_t lookup table1 small inplace");
|
||||
test_lut1_u16( inputData16, resultData16, SIZE_SMALL, myLUT16, "uint16_t lookup table1 small");
|
||||
|
||||
iterations = max( 1, (int)(((uint64_t)base_iterations * SIZE_SMALL) / SIZE) );
|
||||
|
||||
test_lut1_u16( inputData16, inputData16, SIZE, myLUT16, "uint16_t lookup table1 large inplace");
|
||||
test_lut1_u16( inputData16, resultData16, SIZE, myLUT16, "uint16_t lookup table1 large");
|
||||
|
||||
// int16_t
|
||||
iterations = base_iterations;
|
||||
|
||||
test_lut1_16( (int16_t*)inputData16, (int16_t*)inputData16, SIZE_SMALL, (int16_t*)(myLUT16+32768), "int16_t lookup table1 small inplace");
|
||||
test_lut1_16( (int16_t*)inputData16, (int16_t*)resultData16, SIZE_SMALL, (int16_t*)(myLUT16+32768), "int16_t lookup table1 small");
|
||||
|
||||
iterations = max( 1, (int)(((uint64_t)base_iterations * SIZE_SMALL) / SIZE) );
|
||||
|
||||
test_lut1_16( (int16_t*)inputData16, (int16_t*)inputData16, SIZE, (int16_t*)(myLUT16+32768), "int16_t lookup table1 large inplace");
|
||||
test_lut1_16( (int16_t*)inputData16, (int16_t*)resultData16, SIZE, (int16_t*)(myLUT16+32768), "int16_t lookup table1 large");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// the end
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
14
sdk/software/examples/c_prg/loop_induction/Makefile
Normal file
14
sdk/software/examples/c_prg/loop_induction/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
TARGET = loop_induction
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../../bsp
|
||||
GCC_DIR=../../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../../toolchains/picolibc
|
||||
include ../../../bsp/common.mk
|
||||
131
sdk/software/examples/c_prg/loop_induction/loop_induction.c
Normal file
131
sdk/software/examples/c_prg/loop_induction/loop_induction.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
Copyright 2018 Chris Cox
|
||||
Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
|
||||
or a copy at http://stlab.adobe.com/licenses.html )
|
||||
|
||||
|
||||
Goal: Examine performance optimizations related to loop induction variables.
|
||||
|
||||
|
||||
Assumptions:
|
||||
1) The compiler will normalize all loop types and optimize all equally.
|
||||
(this is a necessary step before doing induction variable analysis)
|
||||
|
||||
2) The compiler will remove unused induction variables.
|
||||
This could happen due to several optimizations.
|
||||
|
||||
2) The compiler will recognize induction variables with linear relations (x = a*b + c)
|
||||
and optimize out redundant variables.
|
||||
|
||||
3) The compiler will apply strength reduction to induction variable usage.
|
||||
|
||||
4) The compiler will remove bounds checks by recognizing or adjusting loop limits.
|
||||
(can be an explict loop optimization, or part of range propagation)
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbfe001e0; //UART16550的虚地址
|
||||
unsigned long CONFREG_UART_BASE = 0xbfafff10; //CONFREG模拟UART的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbfafe000; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 100000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
clock_t start_time, end_time;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// this constant may need to be adjusted to give reasonable minimum times
|
||||
// For best results, times should be about 1.0 seconds for the minimum test run
|
||||
int iterations = 10;
|
||||
|
||||
|
||||
// 32000 items, or about 128k of data
|
||||
// this is intended to remain within the L2 cache of most common CPUs
|
||||
const int SIZE = 32000;
|
||||
|
||||
|
||||
// initial value for filling our arrays, may be changed from the command line
|
||||
int init_value = 3;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void fill_random(int32_t * first, int32_t * last) {
|
||||
while (first != last) {
|
||||
*first++ = (int32_t)rand();
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
|
||||
void test_copy(const int32_t *source, int32_t *dest, int count, const char *label) {
|
||||
int i;
|
||||
|
||||
fill_random( dest, dest+count );
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(i = 0; i < iterations; ++i) {
|
||||
int i, j, k;
|
||||
for ( i=0, j=0, k=0; k < count; ++i, ++j, ++k ) {
|
||||
dest[i] = source[j];
|
||||
}
|
||||
}
|
||||
|
||||
end_time = clock();
|
||||
|
||||
if ( memcmp(dest, source, count*sizeof(int32_t)) != 0 )
|
||||
printf("test %s failed\n", label);
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
|
||||
printf("\"%s, %d items\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
// output command for documentation:
|
||||
int i;
|
||||
// for (i = 0; i < argc; ++i)
|
||||
// printf("%s ", argv[i] );
|
||||
// printf("\n");
|
||||
|
||||
if (argc > 1) iterations = atoi(argv[1]);
|
||||
if (argc > 2) init_value = (int) atoi(argv[2]);
|
||||
|
||||
int32_t intSrc[ SIZE ];
|
||||
int32_t intDst[ SIZE ];
|
||||
|
||||
|
||||
srand( (unsigned int)init_value + 123);
|
||||
fill_random( intSrc, intSrc+SIZE );
|
||||
|
||||
|
||||
test_copy( &intSrc[0], &intDst[0], SIZE, "int32_t for induction copy" );
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// the end
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
14
sdk/software/examples/c_prg/memcmp/Makefile
Normal file
14
sdk/software/examples/c_prg/memcmp/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
TARGET = memcmp
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../../bsp
|
||||
GCC_DIR=../../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../../toolchains/picolibc
|
||||
include ../../../bsp/common.mk
|
||||
177
sdk/software/examples/c_prg/memcmp/memcmp.c
Normal file
177
sdk/software/examples/c_prg/memcmp/memcmp.c
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
Copyright 2008-2009 Adobe Systems Incorporated
|
||||
Copyright 2018 Chris Cox
|
||||
Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
|
||||
or a copy at http://stlab.adobe.com/licenses.html )
|
||||
|
||||
|
||||
Goal: Test compiler optimizations related to memcmp and hand coded memcmp loops.
|
||||
|
||||
|
||||
Assumptions:
|
||||
|
||||
1) The compiler will recognize memcmp like loops and optimize appropriately.
|
||||
This could be subtitution of calls to memcmp,
|
||||
or it could be just optimizing the loop to get the best throughput.
|
||||
On modern systems, cache hinting is usually required for best throughput.
|
||||
|
||||
2) The library function memcmp should be optimized for small, medium, and large buffers.
|
||||
ie: low overhead for smaller buffer, highly hinted for large buffers.
|
||||
|
||||
3) The STL functions equal and mismatch should be optimized for small, medium, and large buffers.
|
||||
ie: low overhead for smaller buffers, highly hinted for large buffers.
|
||||
|
||||
|
||||
|
||||
|
||||
NOTE - on some OSes, memcmp calls into the VM system to test for shared pages
|
||||
thus running faster than the DRAM bandwidth would allow on large arrays
|
||||
|
||||
However, on those OSes, calling memcmp can hit mutexes and slow down
|
||||
significantly when called from threads.
|
||||
|
||||
|
||||
NOTE - Linux memcmp returns 0, +-1 instead of the actual difference
|
||||
NOTE - and sometimes Linux memcmp returns 0, +-256 instead of the actual difference
|
||||
|
||||
|
||||
TODO - test performance of unaligned buffers
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/******************************************************************************/
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbfe001e0; //UART16550的虚地址
|
||||
unsigned long CONFREG_UART_BASE = 0xbfafff10; //CONFREG模拟UART的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbfafe000; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 100000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
clock_t start_time, end_time;
|
||||
|
||||
// this constant may need to be adjusted to give reasonable minimum times
|
||||
// For best results, times should be about 1.0 seconds for the minimum test run
|
||||
int iterations = 1;
|
||||
|
||||
|
||||
// 64 Megabytes, intended to be larger than L2 cache on common CPUs
|
||||
// needs to be divisible by 8
|
||||
// 没有这么大内存,给30KB
|
||||
#define SIZE_4K 4096
|
||||
// #define SIZE_3M 3145728
|
||||
#define SIZE_3M 30720
|
||||
|
||||
// initial value for filling our arrays, may be changed from the command line
|
||||
uint8_t init_value = 3;
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
void fill(uint8_t * first, uint8_t * last, uint8_t value) {
|
||||
while (first != last) *first++ = value;
|
||||
}
|
||||
|
||||
|
||||
int forloop_memcmp( const void *first, const void *second, size_t bytes ){
|
||||
const uint8_t *first_byte = (const uint8_t *)first;
|
||||
const uint8_t *second_byte = (const uint8_t *)second;
|
||||
int x;
|
||||
|
||||
for (x = 0; x < bytes; ++x) {
|
||||
if (first_byte[x] != second_byte[x]) {
|
||||
return (first_byte[x] - second_byte[x]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
|
||||
void test_memcmp(const uint8_t *first, const uint8_t *second, int count, bool expected_result) {
|
||||
int i;
|
||||
int bytes = count * sizeof(uint8_t);
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(i = 0; i < iterations; ++i) {
|
||||
// sigh, Linux memcmp is wonky - some return 1, some return 256
|
||||
bool result = (forloop_memcmp( first, second, bytes ) != 0) ;
|
||||
|
||||
// moving this test out of the loop causes unwanted overoptimization
|
||||
if ( result != expected_result )
|
||||
printf("test %s by %d failed (got %d instead of %d)\n", "for loop compare", count, (int)result, (int)expected_result );
|
||||
}
|
||||
|
||||
end_time = clock();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void test_memcmp_sizes(const uint8_t *first, const uint8_t *second, int max_count, bool result) {
|
||||
int i = max_count * sizeof(uint8_t);
|
||||
|
||||
test_memcmp( first, second, max_count, result);
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
|
||||
printf("\"%s %d bytes\" compare result: %s %f sec\n",
|
||||
"for loop compare",
|
||||
i,
|
||||
result ? "false" : "true",
|
||||
time_cost);
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
// our global arrays of numbers to be operated upon
|
||||
|
||||
uint8_t data8u[SIZE_3M/sizeof(uint8_t)];
|
||||
int alignment_pad = 1024;
|
||||
uint8_t data8u_dest[SIZE_3M/sizeof(uint8_t) + 1024]; // leave some room for alignment testing
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
// output command for documentation:
|
||||
int i;
|
||||
|
||||
if (argc > 1) iterations = atoi(argv[1]);
|
||||
if (argc > 2) init_value = (int32_t) atoi(argv[2]);
|
||||
|
||||
|
||||
fill( data8u, data8u+(SIZE_3M/sizeof(uint8_t)), (uint8_t)(init_value) );
|
||||
fill( data8u_dest, data8u_dest+(SIZE_3M/sizeof(uint8_t) + alignment_pad), (uint8_t)(init_value) );
|
||||
test_memcmp_sizes( data8u, data8u_dest, SIZE_3M/sizeof(uint8_t), false);
|
||||
data8u[(SIZE_3M/sizeof(uint8_t))-1] += 1; // last byte in the array
|
||||
test_memcmp_sizes( data8u, data8u_dest, SIZE_3M/sizeof(uint8_t), true);
|
||||
/*
|
||||
test_memcmp_sizes( data8u, data8u_dest, SIZE_1M/sizeof(uint8_t), false);
|
||||
data8u[(SIZE_1M/sizeof(uint8_t))-1] += 1; // last byte in the array
|
||||
test_memcmp_sizes( data8u, data8u_dest, SIZE_1M/sizeof(uint8_t), true);
|
||||
*/
|
||||
test_memcmp_sizes( data8u, data8u_dest, SIZE_4K/sizeof(uint8_t), false);
|
||||
data8u[(SIZE_4K/sizeof(uint8_t))-1] += 1; // last byte in the array
|
||||
test_memcmp_sizes( data8u, data8u_dest, SIZE_4K/sizeof(uint8_t), true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// the end
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
14
sdk/software/examples/c_prg/minmax_sequence/Makefile
Normal file
14
sdk/software/examples/c_prg/minmax_sequence/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
TARGET = minmax_sequence
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../../bsp
|
||||
GCC_DIR=../../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../../toolchains/picolibc
|
||||
include ../../../bsp/common.mk
|
||||
1509
sdk/software/examples/c_prg/minmax_sequence/minmax_sequence.c
Normal file
1509
sdk/software/examples/c_prg/minmax_sequence/minmax_sequence.c
Normal file
File diff suppressed because it is too large
Load Diff
14
sdk/software/examples/c_prg/product_sequence/Makefile
Normal file
14
sdk/software/examples/c_prg/product_sequence/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
TARGET = product_sequence
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../../bsp
|
||||
GCC_DIR=../../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../../toolchains/picolibc
|
||||
include ../../../bsp/common.mk
|
||||
169
sdk/software/examples/c_prg/product_sequence/product_sequence.c
Normal file
169
sdk/software/examples/c_prg/product_sequence/product_sequence.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
Copyright 2008 Adobe Systems Incorporated
|
||||
Copyright 2019 Chris Cox
|
||||
Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
|
||||
or a copy at http://stlab.adobe.com/licenses.html )
|
||||
|
||||
|
||||
Goal: Test performance of various idioms for calculating the product of a sequence.
|
||||
|
||||
|
||||
Assumptions:
|
||||
1) The compiler will optimize product operations.
|
||||
|
||||
2) The compiler may recognize ineffecient product idioms and substitute efficient methods.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbfe001e0; //UART16550的虚地址
|
||||
unsigned long CONFREG_UART_BASE = 0xbfafff10; //CONFREG模拟UART的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbfafe000; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 100000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
clock_t start_time, end_time;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// this constant may need to be adjusted to give reasonable minimum times
|
||||
// For best results, times should be about 1.0 seconds for the minimum test run
|
||||
int iterations = 10;
|
||||
|
||||
|
||||
// 4000 items, or about 32k of data
|
||||
// this is intended to remain within the L2 cache of most common CPUs
|
||||
const int SIZE = 4000;
|
||||
|
||||
|
||||
// initial value for filling our arrays, may be changed from the command line
|
||||
double init_value = 2.1;
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
void fill_f16(float * first, float * last, float value) {
|
||||
while (first != last) *first++ = (float)(value);
|
||||
}
|
||||
|
||||
void fill_f32(double * first, double * last, double value) {
|
||||
while (first != last) *first++ = (double)(value);
|
||||
}
|
||||
|
||||
|
||||
void testOneFunction_f16(const float* first, const int count, const char * label) {
|
||||
int i;
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(i = 0; i < iterations; ++i) {
|
||||
|
||||
float result = (float)(1);
|
||||
for (int j = 0; j < count; ++j) {
|
||||
result = result * first[j];
|
||||
}
|
||||
|
||||
if ( fabs( result - pow(init_value,(double)SIZE) ) > 1.0e-6 )
|
||||
printf("test %s failed\n", label);
|
||||
}
|
||||
|
||||
// need the labels to remain valid until we print the summary
|
||||
end_time = clock();
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
|
||||
printf("\"%s, %d items\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
}
|
||||
|
||||
void testOneFunction_f32(const double* first, const int count, const char * label) {
|
||||
int i;
|
||||
|
||||
start_time = clock();
|
||||
|
||||
for(i = 0; i < iterations; ++i) {
|
||||
|
||||
double result = (double)(1);
|
||||
for (int j = 0; j < count; ++j) {
|
||||
result = result * first[j];
|
||||
}
|
||||
|
||||
if ( fabs( result - pow(init_value,(double)SIZE) ) > 1.0e-6 )
|
||||
printf("test %s failed\n", label);
|
||||
}
|
||||
|
||||
// need the labels to remain valid until we print the summary
|
||||
end_time = clock();
|
||||
|
||||
double time_cost = (end_time - start_time)/ (double)(CLOCKS_PER_SEC);
|
||||
|
||||
printf("\"%s, %d items\" %f sec\n",
|
||||
label,
|
||||
count,
|
||||
time_cost);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void TestOneType_f16()
|
||||
{
|
||||
|
||||
float data[SIZE];
|
||||
|
||||
fill_f16(data, data+SIZE, (float)(init_value));
|
||||
|
||||
testOneFunction_f16( data, SIZE, "float product sequence1" );
|
||||
|
||||
}
|
||||
|
||||
void TestOneType_f32()
|
||||
{
|
||||
|
||||
double data[SIZE];
|
||||
|
||||
fill_f32(data, data+SIZE, (double)(init_value));
|
||||
|
||||
testOneFunction_f32( data, SIZE, "double product sequence1" );
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
// output command for documentation:
|
||||
int i;
|
||||
// for (i = 0; i < argc; ++i)
|
||||
// printf("%s ", argv[i] );
|
||||
// printf("\n");
|
||||
|
||||
if (argc > 1) iterations = atoi(argv[1]);
|
||||
if (argc > 2) init_value = (double) atof(argv[2]);
|
||||
|
||||
|
||||
TestOneType_f16();
|
||||
|
||||
TestOneType_f32();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// the end
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
100
sdk/software/examples/coremark/LICENSE.md
Normal file
100
sdk/software/examples/coremark/LICENSE.md
Normal file
@@ -0,0 +1,100 @@
|
||||
# COREMARK® ACCEPTABLE USE AGREEMENT
|
||||
|
||||
This ACCEPTABLE USE AGREEMENT (this “Agreement”) is offered by Embedded Microprocessor Benchmark Consortium, a California nonprofit corporation (“Licensor”), to users of its CoreMark® software (“Licensee”) exclusively on the following terms.
|
||||
|
||||
Licensor offers benchmarking software (“Software”) pursuant to an open source license, but carefully controls use of its benchmarks and their associated goodwill. Licensor has registered its trademark in one of the benchmarks available through the Software, COREMARK, Ser. No. 85/487,290; Reg. No. 4,179,307 (the “Trademark”), and promotes the use of a standard metric as a benchmark for assessing the performance of embedded systems. Solely on the terms described herein, Licensee may use and display the Trademark in connection with the generation of data regarding measurement and analysis of computer and embedded system benchmarking via the Software (the “Licensed Use”).
|
||||
|
||||
## Article 1 – License Grant.
|
||||
1.1. License. Subject to the terms and conditions of this Agreement, Licensor hereby grants to Licensee, and Licensee hereby accepts from Licensor, a personal, non-exclusive, royalty-free, revocable right and license to use and display the Trademark during the term of this Agreement (the “Term”), solely and exclusively in connection with the Licensed Use. During the Term, Licensee (i) shall not modify or otherwise create derivative works of the Trademark, and (ii) may use the Trademark only to the extent permitted under this License. Neither Licensee nor any affiliate or agent thereof shall otherwise use the Trademark without the prior express written consent of Licensor, which may be withheld in its sole and absolute discretion. All rights not expressly granted to Licensee hereunder shall remain the exclusive property of Licensor.
|
||||
|
||||
1.2. Modifications to the Software. Licensee shall not use the Trademark in connection with any use of a modified, derivative, or otherwise altered copy of the Software.
|
||||
|
||||
1.3. Licensor’s Use. Nothing in this Agreement shall preclude Licensor or any of its successors or assigns from using or permitting other entities to use the Trademark, whether or not such entity directly or indirectly competes or conflicts with Licensee’s Licensed Use in any manner.
|
||||
|
||||
1.4. Term and Termination. This Agreement is perpetual unless terminated by either of the parties. Licensee may terminate this Agreement for convenience, without cause or liability, for any reason or for no reason whatsoever, upon ten (10) business days written notice. Licensor may terminate this Agreement effective immediately upon notice of breach. Upon termination, Licensee shall immediately remove all implementations of the Trademark from the Licensed Use, and delete all digitals files and records of all materials related to the Trademark.
|
||||
|
||||
## Article 2 – Ownership.
|
||||
2.1. Ownership. Licensee acknowledges and agrees that Licensor is the owner of all right, title, and interest in and to the Trademark, and all such right, title, and interest shall remain with Licensor. Licensee shall not contest, dispute, challenge, oppose, or seek to cancel Licensor’s right, title, and interest in and to the Trademark. Licensee shall not prosecute any application for registration of the Trademark. Licensee shall display appropriate notices regarding ownership of the Trademark in connection with the Licensed Use.
|
||||
|
||||
2.2. Goodwill. Licensee acknowledges that Licensee shall not acquire any right, title, or interest in the Trademark by virtue of this Agreement other than the license granted hereunder, and disclaims any such right, title, interest, or ownership. All goodwill and reputation generated by Licensee’s use of the Trademark shall inure to the exclusive benefit of Licensor. Licensee shall not by any act or omission use the Trademark in any manner that disparages or reflects adversely on Licensor or its Licensed Use or reputation. Licensee shall not take any action that would interfere with or prejudice Licensor’s ownership or registration of the Trademark, the validity of the Trademark or the validity of the license granted by this Agreement. If Licensor determines and notifies Licensee that any act taken in connection with the Licensed Use (i) is inaccurate, unlawful or offensive to good taste; (ii) fails to provide for proper trademark notices, or (iii) otherwise violates Licensee’s obligations under this Agreement, the license granted under this Agreement shall terminate.
|
||||
|
||||
## Article 3 – Indemnification.
|
||||
3.1. Indemnification Generally. Licensee agrees to indemnify, defend, and hold harmless (collectively “indemnify” or “indemnification”) Licensor, including Licensor’s members, managers, officers, and employees (collectively “Related Persons”), from and against, and pay or reimburse Licensor and such Related Persons for, any and all third-party actions, claims, demands, proceedings, investigations, inquiries (collectively, “Claims”), and any and all liabilities, obligations, fines, deficiencies, costs, expenses, royalties, losses, and damages (including reasonable outside counsel fees and expenses) associated with such Claims, to the extent that such Claim arises out of (i) Licensee’s material breach of this Agreement, or (ii) any allegation(s) that Licensee’s actions infringe or violate any third-party intellectual property right, including without limitation, any U.S. copyright, patent, or trademark, or are otherwise found to be tortious or criminal (whether or not such indemnified person is a named party in a legal proceeding).
|
||||
|
||||
3.2. Notice and Defense of Claims. Licensor shall promptly notify Licensee of any Claim for which indemnification is sought, following actual knowledge of such Claim, provided however that the failure to give such notice shall not relieve Licensee of its obligations hereunder except to the extent that Licensee is materially prejudiced by such failure. In the event that any third-party Claim is brought, Licensee shall have the right and option to undertake and control the defense of such action with counsel of its choice, provided however that (i) Licensor at its own expense may participate and appear on an equal footing with Licensee in the defense of any such Claim, (ii) Licensor may undertake and control such defense in the event of the material failure of Licensee to undertake and control the same; and (iii) the defense of any Claim relating to the intellectual property rights of Licensor or its licensors and any related counterclaims shall be solely controlled by Licensor with counsel of its choice. Licensee shall not consent to judgment or concede or settle or compromise any Claim without the prior written approval of Licensor (whose approval shall not be unreasonably withheld), unless such concession or settlement or compromise includes a full and unconditional release of Licensor and any applicable Related Persons from all liabilities in respect of such Claim.
|
||||
|
||||
## Article 4 – Miscellaneous.
|
||||
4.1. Relationship of the Parties. This Agreement does not create a partnership, franchise, joint venture, agency, fiduciary, or employment relationship between the parties.
|
||||
|
||||
4.2. No Third-Party Beneficiaries. Except for the rights of Related Persons under Article 3 (Indemnification), there are no third-party beneficiaries to this Agreement.
|
||||
|
||||
4.3. Assignment. Licensee’s rights hereunder are non-assignable, and may not be sublicensed.
|
||||
|
||||
4.4. Equitable Relief. Licensee acknowledges that the remedies available at law for any breach of this Agreement will, by their nature, be inadequate. Accordingly, Licensor may obtain injunctive relief or other equitable relief to restrain a breach or threatened breach of this Agreement or to specifically enforce this Agreement, without proving that any monetary damages have been sustained, and without the requirement of posting of a bond prior to obtaining such equitable relief.
|
||||
|
||||
4.5. Governing Law. This Agreement will be interpreted, construed, and enforced in all respects in accordance with the laws of the State of California, without reference to its conflict of law principles.
|
||||
|
||||
4.6. Attorneys’ Fees. If any legal action, arbitration or other proceeding is brought for the enforcement of this Agreement, or because of an alleged dispute, breach, default, or misrepresentation in connection with any of the provisions of this Agreement, the successful or prevailing party shall be entitled to recover its reasonable attorneys’ fees and other reasonable costs incurred in that action or proceeding, in addition to any other relief to which it may be entitled.
|
||||
|
||||
4.7. Amendment; Waiver. This Agreement may not be amended, nor may any rights under it be waived, except in writing by Licensor.
|
||||
|
||||
4.8. Severability. If any provision of this Agreement is held by a court of competent jurisdiction to be contrary to law, the provision shall be modified by the court and interpreted so as best to accomplish the objectives of the original provision to the fullest extent
|
||||
permitted by law, and the remaining provisions of this Agreement shall remain in effect.
|
||||
|
||||
4.9. Entire Agreement. This Agreement constitutes the entire agreement between the parties and supersedes all prior and contemporaneous agreements, proposals or representations, written or oral, concerning its subject matter.
|
||||
|
||||
|
||||
# Apache License
|
||||
|
||||
Version 2.0, January 2004
|
||||
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
## TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||
|
||||
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
25
sdk/software/examples/coremark/Makefile
Normal file
25
sdk/software/examples/coremark/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
TARGET = coremark
|
||||
|
||||
C_SRCS := \
|
||||
core_list_join.c \
|
||||
core_main.c \
|
||||
core_matrix.c \
|
||||
core_state.c \
|
||||
core_util.c \
|
||||
core_portme.c \
|
||||
|
||||
CFLAGS := -O3 -funroll-all-loops -finline-limit=200 -ftree-dominator-opts -fno-if-conversion2 -fselective-scheduling -fno-code-hoisting -fno-common -falign-functions=4 -falign-jumps=4 -falign-loops=4
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
CFLAGS += -DFLAGS_STR=\""$(CFLAGS)"\"
|
||||
CFLAGS += -g
|
||||
#配置迭代次数
|
||||
CFLAGS += -DITERATIONS=1
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../bsp
|
||||
GCC_DIR=../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../toolchains/picolibc
|
||||
include ../../bsp/common.mk
|
||||
398
sdk/software/examples/coremark/README.md
Normal file
398
sdk/software/examples/coremark/README.md
Normal file
@@ -0,0 +1,398 @@
|
||||
|
||||
# Introduction
|
||||
|
||||
CoreMark's primary goals are simplicity and providing a method for testing only a processor's core features. For more information about EEMBC's comprehensive embedded benchmark suites, please see www.eembc.org.
|
||||
|
||||
For a more compute-intensive version of CoreMark that uses larger datasets and execution loops taken from common applications, please check out EEMBC's [CoreMark-PRO](https://www.github.com/eembc/coremark-pro) benchmark, also on GitHub.
|
||||
|
||||
# Building and Running
|
||||
|
||||
To build and run the benchmark, type
|
||||
|
||||
`> make`
|
||||
|
||||
Full results are available in the files `run1.log` and `run2.log`. CoreMark result can be found in `run1.log`.
|
||||
|
||||
## Cross Compiling
|
||||
|
||||
For cross compile platforms please adjust `core_portme.mak`, `core_portme.h` (and possibly `core_portme.c`) according to the specific platform used. When porting to a new platform, it is recommended to copy one of the default port folders (e.g. `mkdir <platform> && cp linux/* <platform>`), adjust the porting files, and run:
|
||||
~~~
|
||||
% make PORT_DIR=<platform>
|
||||
~~~
|
||||
|
||||
## Make Targets
|
||||
`run` - Default target, creates `run1.log` and `run2.log`.
|
||||
`run1.log` - Run the benchmark with performance parameters, and output to `run1.log`
|
||||
`run2.log` - Run the benchmark with validation parameters, and output to `run2.log`
|
||||
`run3.log` - Run the benchmark with profile generation parameters, and output to `run3.log`
|
||||
`compile` - compile the benchmark executable
|
||||
`link` - link the benchmark executable
|
||||
`check` - test MD5 of sources that may not be modified
|
||||
`clean` - clean temporary files
|
||||
|
||||
### Make flag: `ITERATIONS`
|
||||
By default, the benchmark will run between 10-100 seconds. To override, use `ITERATIONS=N`
|
||||
~~~
|
||||
% make ITERATIONS=10
|
||||
~~~
|
||||
Will run the benchmark for 10 iterations. It is recommended to set a specific number of iterations in certain situations e.g.:
|
||||
|
||||
* Running with a simulator
|
||||
* Measuring power/energy
|
||||
* Timing cannot be restarted
|
||||
|
||||
Minimum required run time: **Results are only valid for reporting if the benchmark ran for at least 10 secs!**
|
||||
|
||||
### Make flag: `XCFLAGS`
|
||||
To add compiler flags from the command line, use `XCFLAGS` e.g.:
|
||||
|
||||
~~~
|
||||
% make XCFLAGS="-g -DMULTITHREAD=4 -DUSE_FORK=1"
|
||||
~~~
|
||||
|
||||
### Make flag: `CORE_DEBUG`
|
||||
|
||||
Define to compile for a debug run if you get incorrect CRC.
|
||||
|
||||
~~~
|
||||
% make XCFLAGS="-DCORE_DEBUG=1"
|
||||
~~~
|
||||
|
||||
### Make flag: `REBUILD`
|
||||
|
||||
Force a rebuild of the executable.
|
||||
|
||||
## Systems Without `make`
|
||||
The following files need to be compiled:
|
||||
* `core_list_join.c`
|
||||
* `core_main.c`
|
||||
* `core_matrix.c`
|
||||
* `core_state.c`
|
||||
* `core_util.c`
|
||||
* `PORT_DIR/core_portme.c`
|
||||
|
||||
For example:
|
||||
~~~
|
||||
% gcc -O2 -o coremark.exe core_list_join.c core_main.c core_matrix.c core_state.c core_util.c simple/core_portme.c -DPERFORMANCE_RUN=1 -DITERATIONS=1000
|
||||
% ./coremark.exe > run1.log
|
||||
~~~
|
||||
The above will compile the benchmark for a performance run and 1000 iterations. Output is redirected to `run1.log`.
|
||||
|
||||
# Parallel Execution
|
||||
Use `XCFLAGS=-DMULTITHREAD=N` where N is number of threads to run in parallel. Several implementations are available to execute in multiple contexts, or you can implement your own in `core_portme.c`.
|
||||
|
||||
~~~
|
||||
% make XCFLAGS="-DMULTITHREAD=4 -DUSE_PTHREAD"
|
||||
~~~
|
||||
|
||||
The above will compile the benchmark for execution on 4 cores, using POSIX Threads API.
|
||||
|
||||
Note: linking may fail on the previous command if your linker does not automatically add the `pthread` library. If you encounter `undefined reference` errors, please modify the `core_portme.mak` file for your platform, (e.g. `linux64/core_portme.mak`) and add `-lpthread` to the `LFLAGS_END` parameter.
|
||||
|
||||
# Run Parameters for the Benchmark Executable
|
||||
CoreMark's executable takes several parameters as follows (but only if `main()` accepts arguments):
|
||||
1st - A seed value used for initialization of data.
|
||||
2nd - A seed value used for initialization of data.
|
||||
3rd - A seed value used for initialization of data.
|
||||
4th - Number of iterations (0 for auto : default value)
|
||||
5th - Reserved for internal use.
|
||||
6th - Reserved for internal use.
|
||||
7th - For malloc users only, ovreride the size of the input data buffer.
|
||||
|
||||
The run target from make will run coremark with 2 different data initialization seeds.
|
||||
|
||||
## Alternative parameters:
|
||||
If not using `malloc` or command line arguments are not supported, the buffer size
|
||||
for the algorithms must be defined via the compiler define `TOTAL_DATA_SIZE`.
|
||||
`TOTAL_DATA_SIZE` must be set to 2000 bytes (default) for standard runs.
|
||||
The default for such a target when testing different configurations could be:
|
||||
|
||||
~~~
|
||||
% make XCFLAGS="-DTOTAL_DATA_SIZE=6000 -DMAIN_HAS_NOARGC=1"
|
||||
~~~
|
||||
|
||||
# Submitting Results
|
||||
|
||||
CoreMark results can be submitted on the web. Open a web browser and go to the [submission page](https://www.eembc.org/coremark/submit.php). After registering an account you may enter a score.
|
||||
|
||||
# Run Rules
|
||||
What is and is not allowed.
|
||||
|
||||
## Required
|
||||
1. The benchmark needs to run for at least 10 seconds.
|
||||
2. All validation must succeed for seeds `0,0,0x66` and `0x3415,0x3415,0x66`, buffer size of 2000 bytes total.
|
||||
* If not using command line arguments to main:
|
||||
~~~
|
||||
% make XCFLAGS="-DPERFORMANCE_RUN=1" REBUILD=1 run1.log
|
||||
% make XCFLAGS="-DVALIDATION_RUN=1" REBUILD=1 run2.log
|
||||
~~~
|
||||
3. If using profile guided optimization, profile must be generated using seeds of `8,8,8`, and buffer size of 1200 bytes total.
|
||||
~~~
|
||||
% make XCFLAGS="-DTOTAL_DATA_SIZE=1200 -DPROFILE_RUN=1" REBUILD=1 run3.log
|
||||
~~~
|
||||
4. All source files must be compiled with the same flags.
|
||||
5. All data type sizes must match size in bits such that:
|
||||
* `ee_u8` is an unsigned 8-bit datatype.
|
||||
* `ee_s16` is a signed 16-bit datatype.
|
||||
* `ee_u16` is an unsigned 16-bit datatype.
|
||||
* `ee_s32` is a signed 32-bit datatype.
|
||||
* `ee_u32` is an unsigned 32-bit datatype.
|
||||
|
||||
## Allowed
|
||||
|
||||
1. Changing number of iterations
|
||||
2. Changing toolchain and build/load/run options
|
||||
3. Changing method of acquiring a data memory block
|
||||
5. Changing the method of acquiring seed values
|
||||
6. Changing implementation `in core_portme.c`
|
||||
7. Changing configuration values in `core_portme.h`
|
||||
8. Changing `core_portme.mak`
|
||||
|
||||
## NOT ALLOWED
|
||||
1. Changing of source file other then `core_portme*` (use `make check` to validate)
|
||||
|
||||
# Reporting rules
|
||||
Use the following syntax to report results on a data sheet:
|
||||
|
||||
CoreMark 1.0 : N / C [/ P] [/ M]
|
||||
|
||||
N - Number of iterations per second with seeds 0,0,0x66,size=2000)
|
||||
|
||||
C - Compiler version and flags
|
||||
|
||||
P - Parameters such as data and code allocation specifics
|
||||
|
||||
* This parameter *may* be omitted if all data was allocated on the heap in RAM.
|
||||
* This parameter *may not* be omitted when reporting CoreMark/MHz
|
||||
|
||||
M - Type of parallel execution (if used) and number of contexts
|
||||
* This parameter may be omitted if parallel execution was not used.
|
||||
|
||||
e.g.:
|
||||
|
||||
~~~
|
||||
CoreMark 1.0 : 128 / GCC 4.1.2 -O2 -fprofile-use / Heap in TCRAM / FORK:2
|
||||
~~~
|
||||
or
|
||||
~~~
|
||||
CoreMark 1.0 : 1400 / GCC 3.4 -O4
|
||||
~~~
|
||||
|
||||
If reporting scaling results, the results must be reported as follows:
|
||||
|
||||
CoreMark/MHz 1.0 : N / C / P [/ M]
|
||||
|
||||
P - When reporting scaling results, memory parameter must also indicate memory frequency:core frequency ratio.
|
||||
1. If the core has cache and cache frequency to core frequency ratio is configurable, that must also be included.
|
||||
|
||||
e.g.:
|
||||
|
||||
~~~
|
||||
CoreMark/MHz 1.0 : 1.47 / GCC 4.1.2 -O2 / DDR3(Heap) 30:1 Memory 1:1 Cache
|
||||
~~~
|
||||
|
||||
# Log File Format
|
||||
The log files have the following format
|
||||
|
||||
~~~
|
||||
2K performance run parameters for coremark. (Run type)
|
||||
CoreMark Size : 666 (Buffer size)
|
||||
Total ticks : 25875 (platform dependent value)
|
||||
Total time (secs) : 25.875000 (actual time in seconds)
|
||||
Iterations/Sec : 3864.734300 (Performance value to report)
|
||||
Iterations : 100000 (number of iterations used)
|
||||
Compiler version : GCC3.4.4 (Compiler and version)
|
||||
Compiler flags : -O2 (Compiler and linker flags)
|
||||
Memory location : Code in flash, data in on chip RAM
|
||||
seedcrc : 0xe9f5 (identifier for the input seeds)
|
||||
[0]crclist : 0xe714 (validation for list part)
|
||||
[0]crcmatrix : 0x1fd7 (validation for matrix part)
|
||||
[0]crcstate : 0x8e3a (validation for state part)
|
||||
[0]crcfinal : 0x33ff (iteration dependent output)
|
||||
Correct operation validated. See README.md for run and reporting rules. (*Only when run is successful*)
|
||||
CoreMark 1.0 : 6508.490622 / GCC3.4.4 -O2 / Heap (*Only on a successful performance run*)
|
||||
~~~
|
||||
|
||||
# Theory of Operation
|
||||
|
||||
This section describes the initial goals of CoreMark and their implementation.
|
||||
|
||||
## Small and easy to understand
|
||||
|
||||
* X number of source code lines for timed portion of the benchmark.
|
||||
* Meaningful names for variables and functions.
|
||||
* Comments for each block of code more than 10 lines long.
|
||||
|
||||
## Portability
|
||||
|
||||
A thin abstraction layer will be provided for I/O and timing in a separate file. All I/O and timing of the benchmark will be done through this layer.
|
||||
|
||||
### Code / data size
|
||||
|
||||
* Compile with gcc on x86 and make sure all sizes are according to requirements.
|
||||
* If dynamic memory allocation is used, take total memory allocated into account as well.
|
||||
* Avoid recursive functions and keep track of stack usage.
|
||||
* Use the same memory block as data site for all algorithms, and initialize the data before each algorithm – while this means that initialization with data happens during the timed portion, it will only happen once during the timed portion and so have negligible effect on the results.
|
||||
|
||||
## Controlled output
|
||||
|
||||
This may be the most difficult goal. Compilers are constantly improving and getting better at analyzing code. To create work that cannot be computed at compile time and must be computed at run time, we will rely on two assumptions:
|
||||
|
||||
* Some system functions (e.g. time, scanf) and parameters cannot be computed at compile time. In most cases, marking a variable volatile means the compiler is force to read this variable every time it is read. This will be used to introduce a factor into the input that cannot be precomputed at compile time. Since the results are input dependent, that will make sure that computation has to happen at run time.
|
||||
|
||||
* Either a system function or I/O (e.g. scanf) or command line parameters or volatile variables will be used before the timed portion to generate data which is not available at compile time. Specific method used is not relevant as long as it can be controlled, and that it cannot be computed or eliminated by the compiler at compile time. E.g. if the clock() functions is a compiler stub, it may not be used. The derived values will be reported on the output so that verification can be done on a different machine.
|
||||
|
||||
* We cannot rely on command line parameters since some embedded systems do not have the capability to provide command line parameters. All 3 methods above will be implemented (time based, scanf and command line parameters) and all 3 are valid if the compiler cannot determine the value at compile time.
|
||||
|
||||
* It is important to note that The actual values that are to be supplied at run time will be standardized. The methodology is not intended to provide random data, but simply to provide controlled data that cannot be precomputed at compile time.
|
||||
|
||||
* Printed results must be valid at run time. This will be used to make sure the computation has been executed.
|
||||
|
||||
* Some embedded systems do not provide “printf” or other I/O functionality. All I/O will be done through a thin abstraction interface to allow execution on such systems (e.g. allow output via JTAG).
|
||||
|
||||
## Key Algorithms
|
||||
|
||||
### Linked List
|
||||
|
||||
The following linked list structure will be used:
|
||||
|
||||
~~~
|
||||
typedef struct list_data_s {
|
||||
ee_s16 data16;
|
||||
ee_s16 idx;
|
||||
} list_data;
|
||||
|
||||
typedef struct list_head_s {
|
||||
struct list_head_s *next;
|
||||
struct list_data_s *info;
|
||||
} list_head;
|
||||
~~~
|
||||
|
||||
While adding a level of indirection accessing the data, this structure is realistic and used in many embedded applications for small to medium lists.
|
||||
|
||||
The list itself will be initialized on a block of memory that will be passed in to the initialization function. While in general linked lists use malloc for new nodes, embedded applications sometime control the memory for small data structures such as arrays and lists directly to avoid the overhead of system calls, so this approach is realistic.
|
||||
|
||||
The linked list will be initialized such that 1/4 of the list pointers point to sequential areas in memory, and 3/4 of the list pointers are distributed in a non sequential manner. This is done to emulate a linked list that had add/remove happen for a while disrupting the neat order, and then a series of adds that are likely to come from sequential memory locations.
|
||||
|
||||
For the benchmark itself:
|
||||
- Multiple find operations are going to be performed. These find operations may result in the whole list being traversed. The result of each find will become part of the output chain.
|
||||
- The list will be sorted using merge sort based on the data16 value, and then derive CRC of the data16 item in order for part of the list. The CRC will become part of the output chain.
|
||||
- The list will be sorted again using merge sort based on the idx value. This sort will guarantee that the list is returned to the primary state before leaving the function, so that multiple iterations of the function will have the same result. CRC of the data16 for part of the list will again be calculated and become part of the output chain.
|
||||
|
||||
The actual `data16` in each cell will be pseudo random based on a single 16b input that cannot be determined at compile time. In addition, the part of the list which is used for CRC will also be passed to the function, and determined based on an input that cannot be determined at run time.
|
||||
|
||||
### Matrix Multiply
|
||||
|
||||
This very simple algorithm forms the basis of many more complex algorithms. The tight inner loop is the focus of many optimizations (compiler as well as hardware based) and is thus relevant for embedded processing.
|
||||
|
||||
The total available data space will be divided to 3 parts:
|
||||
1. NxN matrix A.
|
||||
2. NxN matrix B.
|
||||
3. NxN matrix C.
|
||||
|
||||
E.g. for 2K we will have 3 12x12 matrices (assuming data type of 32b 12(len)*12(wid)*4(size)*3(num) =1728 bytes).
|
||||
|
||||
Matrix A will be initialized with small values (upper 3/4 of the bits all zero).
|
||||
Matrix B will be initialized with medium values (upper half of the bits all zero).
|
||||
Matrix C will be used for the result.
|
||||
|
||||
For the benchmark itself:
|
||||
- Multiple A by a constant into C, add the upper bits of each of the values in the result matrix. The result will become part of the output chain.
|
||||
- Multiple A by column X of B into C, add the upper bits of each of the values in the result matrix. The result will become part of the output chain.
|
||||
- Multiple A by B into C, add the upper bits of each of the values in the result matrix. The result will become part of the output chain.
|
||||
|
||||
The actual values for A and B must be derived based on input that is not available at compile time.
|
||||
|
||||
### State Machine
|
||||
|
||||
This part of the code needs to exercise switch and if statements. As such, we will use a small Moore state machine. In particular, this will be a state machine that identifies string input as numbers and divides them according to format.
|
||||
|
||||
The state machine will parse the input string until either a “,” separator or end of input is encountered. An invalid number will cause the state machine to return invalid state and a valid number will cause the state machine to return with type of number format (int/float/scientific).
|
||||
|
||||
This code will perform a realistic task, be small enough to easily understand, and exercise the required functionality. The other option used in embedded systems is a mealy based state machine, which is driven by a table. The table then determines the number of states and complexity of transitions. This approach, however, tests mainly the load/store and function call mechanisms and less the handling of branches. If analysis of the final results shows that the load/store functionality of the processor is not exercised thoroughly, it may be a good addition to the benchmark (codesize allowing).
|
||||
|
||||
For input, the memory block will be initialized with comma separated values of mixed formats, as well as invalid inputs.
|
||||
|
||||
For the benchmark itself:
|
||||
- Invoke the state machine on all of the input and count final states and state transitions. CRC of all final states and transitions will become part of the output chain.
|
||||
- Modify the input at intervals (inject errors) and repeat the state machine operation.
|
||||
- Modify the input back to original form.
|
||||
|
||||
The actual input must be initialized based on data that cannot be determined at compile time. In addition the intervals for modification of the input and the actual modification must be based on input that cannot be determined at compile time.
|
||||
|
||||
# Validation
|
||||
|
||||
This release was tested on the following platforms:
|
||||
* x86 cygwin and gcc 3.4 (Quad, dual and single core systems)
|
||||
* x86 linux (Ubuntu/Fedora) and gcc (4.2/4.1) (Quad and single core systems)
|
||||
* MIPS64 BE linux and gcc 3.4 16 cores system
|
||||
* MIPS32 BE linux with CodeSourcery compiler 4.2-177 on Malta/Linux with a 1004K 3-core system
|
||||
* PPC simulator with gcc 4.2.2 (No OS)
|
||||
* PPC 64b BE linux (yellowdog) with gcc 3.4 and 4.1 (Dual core system)
|
||||
* BF533 with VDSP50
|
||||
* Renesas R8C/H8 MCU with HEW 4.05
|
||||
* NXP LPC1700 armcc v4.0.0.524
|
||||
* NEC 78K with IAR v4.61
|
||||
* ARM simulator with armcc v4
|
||||
|
||||
# Memory Analysis
|
||||
|
||||
Valgrind 3.4.0 used and no errors reported.
|
||||
|
||||
# Balance Analysis
|
||||
|
||||
Number of instructions executed for each function tested with cachegrind and found balanced with gcc and -O0.
|
||||
|
||||
# Statistics
|
||||
|
||||
Lines:
|
||||
~~~
|
||||
Lines Blank Cmnts Source AESL
|
||||
===== ===== ===== ===== ========== =======================================
|
||||
469 66 170 251 627.5 core_list_join.c (C)
|
||||
330 18 54 268 670.0 core_main.c (C)
|
||||
256 32 80 146 365.0 core_matrix.c (C)
|
||||
240 16 51 186 465.0 core_state.c (C)
|
||||
165 11 20 134 335.0 core_util.c (C)
|
||||
150 23 36 98 245.0 coremark.h (C)
|
||||
1610 166 411 1083 2707.5 ----- Benchmark ----- (6 files)
|
||||
293 15 74 212 530.0 linux/core_portme.c (C)
|
||||
235 30 104 104 260.0 linux/core_portme.h (C)
|
||||
528 45 178 316 790.0 ----- Porting ----- (2 files)
|
||||
|
||||
* For comparison, here are the stats for Dhrystone
|
||||
Lines Blank Cmnts Source AESL
|
||||
===== ===== ===== ===== ========== =======================================
|
||||
311 15 242 54 135.0 dhry.h (C)
|
||||
789 132 119 553 1382.5 dhry_1.c (C)
|
||||
186 26 68 107 267.5 dhry_2.c (C)
|
||||
1286 173 429 714 1785.0 ----- C ----- (3 files)
|
||||
~~~
|
||||
|
||||
# Credits
|
||||
Many thanks to all of the individuals who helped with the development or testing of CoreMark including (Sorted by company name; note that company names may no longer be accurate as this was written in 2009).
|
||||
* Alan Anderson, ADI
|
||||
* Adhikary Rajiv, ADI
|
||||
* Elena Stohr, ARM
|
||||
* Ian Rickards, ARM
|
||||
* Andrew Pickard, ARM
|
||||
* Trent Parker, CAVIUM
|
||||
* Shay Gal-On, EEMBC
|
||||
* Markus Levy, EEMBC
|
||||
* Peter Torelli, EEMBC
|
||||
* Ron Olson, IBM
|
||||
* Eyal Barzilay, MIPS
|
||||
* Jens Eltze, NEC
|
||||
* Hirohiko Ono, NEC
|
||||
* Ulrich Drees, NEC
|
||||
* Frank Roscheda, NEC
|
||||
* Rob Cosaro, NXP
|
||||
* Shumpei Kawasaki, RENESAS
|
||||
|
||||
# Legal
|
||||
Please refer to LICENSE.md in this reposity for a description of your rights to use this code.
|
||||
|
||||
# Copyright
|
||||
Copyright © 2009 EEMBC All rights reserved.
|
||||
CoreMark is a trademark of EEMBC and EEMBC is a registered trademark of the Embedded Microprocessor Benchmark Consortium.
|
||||
|
||||
599
sdk/software/examples/coremark/core_list_join.c
Normal file
599
sdk/software/examples/coremark/core_list_join.c
Normal file
@@ -0,0 +1,599 @@
|
||||
/*
|
||||
Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Original Author: Shay Gal-on
|
||||
*/
|
||||
|
||||
#include "coremark.h"
|
||||
/*
|
||||
Topic: Description
|
||||
Benchmark using a linked list.
|
||||
|
||||
Linked list is a common data structure used in many applications.
|
||||
|
||||
For our purposes, this will excercise the memory units of the processor.
|
||||
In particular, usage of the list pointers to find and alter data.
|
||||
|
||||
We are not using Malloc since some platforms do not support this
|
||||
library.
|
||||
|
||||
Instead, the memory block being passed in is used to create a list,
|
||||
and the benchmark takes care not to add more items then can be
|
||||
accomodated by the memory block. The porting layer will make sure
|
||||
that we have a valid memory block.
|
||||
|
||||
All operations are done in place, without using any extra memory.
|
||||
|
||||
The list itself contains list pointers and pointers to data items.
|
||||
Data items contain the following:
|
||||
|
||||
idx - An index that captures the initial order of the list.
|
||||
data - Variable data initialized based on the input parameters. The 16b
|
||||
are divided as follows: o Upper 8b are backup of original data. o Bit 7
|
||||
indicates if the lower 7 bits are to be used as is or calculated. o Bits 0-2
|
||||
indicate type of operation to perform to get a 7b value. o Bits 3-6 provide
|
||||
input for the operation.
|
||||
|
||||
*/
|
||||
|
||||
/* local functions */
|
||||
|
||||
list_head *core_list_find(list_head *list, list_data *info);
|
||||
list_head *core_list_reverse(list_head *list);
|
||||
list_head *core_list_remove(list_head *item);
|
||||
list_head *core_list_undo_remove(list_head *item_removed,
|
||||
list_head *item_modified);
|
||||
list_head *core_list_insert_new(list_head * insert_point,
|
||||
list_data * info,
|
||||
list_head **memblock,
|
||||
list_data **datablock,
|
||||
list_head * memblock_end,
|
||||
list_data * datablock_end);
|
||||
typedef ee_s32 (*list_cmp)(list_data *a, list_data *b, core_results *res);
|
||||
list_head *core_list_mergesort(list_head * list,
|
||||
list_cmp cmp,
|
||||
core_results *res);
|
||||
|
||||
ee_s16
|
||||
calc_func(ee_s16 *pdata, core_results *res)
|
||||
{
|
||||
ee_s16 data = *pdata;
|
||||
ee_s16 retval;
|
||||
ee_u8 optype
|
||||
= (data >> 7)
|
||||
& 1; /* bit 7 indicates if the function result has been cached */
|
||||
if (optype) /* if cached, use cache */
|
||||
return (data & 0x007f);
|
||||
else
|
||||
{ /* otherwise calculate and cache the result */
|
||||
ee_s16 flag = data & 0x7; /* bits 0-2 is type of function to perform */
|
||||
ee_s16 dtype
|
||||
= ((data >> 3)
|
||||
& 0xf); /* bits 3-6 is specific data for the operation */
|
||||
dtype |= dtype << 4; /* replicate the lower 4 bits to get an 8b value */
|
||||
switch (flag)
|
||||
{
|
||||
case 0:
|
||||
if (dtype < 0x22) /* set min period for bit corruption */
|
||||
dtype = 0x22;
|
||||
retval = core_bench_state(res->size,
|
||||
res->memblock[3],
|
||||
res->seed1,
|
||||
res->seed2,
|
||||
dtype,
|
||||
res->crc);
|
||||
if (res->crcstate == 0)
|
||||
res->crcstate = retval;
|
||||
break;
|
||||
case 1:
|
||||
retval = core_bench_matrix(&(res->mat), dtype, res->crc);
|
||||
if (res->crcmatrix == 0)
|
||||
res->crcmatrix = retval;
|
||||
break;
|
||||
default:
|
||||
retval = data;
|
||||
break;
|
||||
}
|
||||
res->crc = crcu16(retval, res->crc);
|
||||
retval &= 0x007f;
|
||||
*pdata = (data & 0xff00) | 0x0080 | retval; /* cache the result */
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
/* Function: cmp_complex
|
||||
Compare the data item in a list cell.
|
||||
|
||||
Can be used by mergesort.
|
||||
*/
|
||||
ee_s32
|
||||
cmp_complex(list_data *a, list_data *b, core_results *res)
|
||||
{
|
||||
ee_s16 val1 = calc_func(&(a->data16), res);
|
||||
ee_s16 val2 = calc_func(&(b->data16), res);
|
||||
return val1 - val2;
|
||||
}
|
||||
|
||||
/* Function: cmp_idx
|
||||
Compare the idx item in a list cell, and regen the data.
|
||||
|
||||
Can be used by mergesort.
|
||||
*/
|
||||
ee_s32
|
||||
cmp_idx(list_data *a, list_data *b, core_results *res)
|
||||
{
|
||||
if (res == NULL)
|
||||
{
|
||||
a->data16 = (a->data16 & 0xff00) | (0x00ff & (a->data16 >> 8));
|
||||
b->data16 = (b->data16 & 0xff00) | (0x00ff & (b->data16 >> 8));
|
||||
}
|
||||
return a->idx - b->idx;
|
||||
}
|
||||
|
||||
void
|
||||
copy_info(list_data *to, list_data *from)
|
||||
{
|
||||
to->data16 = from->data16;
|
||||
to->idx = from->idx;
|
||||
}
|
||||
|
||||
/* Benchmark for linked list:
|
||||
- Try to find multiple data items.
|
||||
- List sort
|
||||
- Operate on data from list (crc)
|
||||
- Single remove/reinsert
|
||||
* At the end of this function, the list is back to original state
|
||||
*/
|
||||
ee_u16
|
||||
core_bench_list(core_results *res, ee_s16 finder_idx)
|
||||
{
|
||||
ee_u16 retval = 0;
|
||||
ee_u16 found = 0, missed = 0;
|
||||
list_head *list = res->list;
|
||||
ee_s16 find_num = res->seed3;
|
||||
list_head *this_find;
|
||||
list_head *finder, *remover;
|
||||
list_data info;
|
||||
ee_s16 i;
|
||||
|
||||
info.idx = finder_idx;
|
||||
/* find <find_num> values in the list, and change the list each time
|
||||
* (reverse and cache if value found) */
|
||||
for (i = 0; i < find_num; i++)
|
||||
{
|
||||
info.data16 = (i & 0xff);
|
||||
this_find = core_list_find(list, &info);
|
||||
list = core_list_reverse(list);
|
||||
if (this_find == NULL)
|
||||
{
|
||||
missed++;
|
||||
retval += (list->next->info->data16 >> 8) & 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
found++;
|
||||
if (this_find->info->data16 & 0x1) /* use found value */
|
||||
retval += (this_find->info->data16 >> 9) & 1;
|
||||
/* and cache next item at the head of the list (if any) */
|
||||
if (this_find->next != NULL)
|
||||
{
|
||||
finder = this_find->next;
|
||||
this_find->next = finder->next;
|
||||
finder->next = list->next;
|
||||
list->next = finder;
|
||||
}
|
||||
}
|
||||
if (info.idx >= 0)
|
||||
info.idx++;
|
||||
#if CORE_DEBUG
|
||||
ee_printf("List find %d: [%d,%d,%d]\n", i, retval, missed, found);
|
||||
#endif
|
||||
}
|
||||
retval += found * 4 - missed;
|
||||
/* sort the list by data content and remove one item*/
|
||||
if (finder_idx > 0)
|
||||
list = core_list_mergesort(list, cmp_complex, res);
|
||||
remover = core_list_remove(list->next);
|
||||
/* CRC data content of list from location of index N forward, and then undo
|
||||
* remove */
|
||||
finder = core_list_find(list, &info);
|
||||
if (!finder)
|
||||
finder = list->next;
|
||||
while (finder)
|
||||
{
|
||||
retval = crc16(list->info->data16, retval);
|
||||
finder = finder->next;
|
||||
}
|
||||
#if CORE_DEBUG
|
||||
ee_printf("List sort 1: %04x\n", retval);
|
||||
#endif
|
||||
remover = core_list_undo_remove(remover, list->next);
|
||||
/* sort the list by index, in effect returning the list to original state */
|
||||
list = core_list_mergesort(list, cmp_idx, NULL);
|
||||
/* CRC data content of list */
|
||||
finder = list->next;
|
||||
while (finder)
|
||||
{
|
||||
retval = crc16(list->info->data16, retval);
|
||||
finder = finder->next;
|
||||
}
|
||||
#if CORE_DEBUG
|
||||
ee_printf("List sort 2: %04x\n", retval);
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
/* Function: core_list_init
|
||||
Initialize list with data.
|
||||
|
||||
Parameters:
|
||||
blksize - Size of memory to be initialized.
|
||||
memblock - Pointer to memory block.
|
||||
seed - Actual values chosen depend on the seed parameter.
|
||||
The seed parameter MUST be supplied from a source that cannot be
|
||||
determined at compile time
|
||||
|
||||
Returns:
|
||||
Pointer to the head of the list.
|
||||
|
||||
*/
|
||||
list_head *
|
||||
core_list_init(ee_u32 blksize, list_head *memblock, ee_s16 seed)
|
||||
{
|
||||
/* calculated pointers for the list */
|
||||
ee_u32 per_item = 16 + sizeof(struct list_data_s);
|
||||
ee_u32 size = (blksize / per_item)
|
||||
- 2; /* to accomodate systems with 64b pointers, and make sure
|
||||
same code is executed, set max list elements */
|
||||
list_head *memblock_end = memblock + size;
|
||||
list_data *datablock = (list_data *)(memblock_end);
|
||||
list_data *datablock_end = datablock + size;
|
||||
/* some useful variables */
|
||||
ee_u32 i;
|
||||
list_head *finder, *list = memblock;
|
||||
list_data info;
|
||||
|
||||
/* create a fake items for the list head and tail */
|
||||
list->next = NULL;
|
||||
list->info = datablock;
|
||||
list->info->idx = 0x0000;
|
||||
list->info->data16 = (ee_s16)0x8080;
|
||||
memblock++;
|
||||
datablock++;
|
||||
info.idx = 0x7fff;
|
||||
info.data16 = (ee_s16)0xffff;
|
||||
core_list_insert_new(
|
||||
list, &info, &memblock, &datablock, memblock_end, datablock_end);
|
||||
|
||||
/* then insert size items */
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
ee_u16 datpat = ((ee_u16)(seed ^ i) & 0xf);
|
||||
ee_u16 dat
|
||||
= (datpat << 3) | (i & 0x7); /* alternate between algorithms */
|
||||
info.data16 = (dat << 8) | dat; /* fill the data with actual data and
|
||||
upper bits with rebuild value */
|
||||
core_list_insert_new(
|
||||
list, &info, &memblock, &datablock, memblock_end, datablock_end);
|
||||
}
|
||||
/* and now index the list so we know initial seed order of the list */
|
||||
finder = list->next;
|
||||
i = 1;
|
||||
while (finder->next != NULL)
|
||||
{
|
||||
if (i < size / 5) /* first 20% of the list in order */
|
||||
finder->info->idx = i++;
|
||||
else
|
||||
{
|
||||
volatile ee_u16 pat = (ee_u16)(i++ ^ seed); /* get a pseudo random number */
|
||||
finder->info->idx = 0x3fff & (((i & 0x07) << 8)| pat); /* make sure the mixed items end up after the ones in sequence */
|
||||
//*( volatile int * ) ( 0x40000000 ) = pat;
|
||||
//*( volatile int * ) ( 0x40000004 ) = ((i & 0x07) << 8) | pat;
|
||||
//*( volatile int * ) ( 0x40000008 ) = finder->info->idx;
|
||||
//ee_printf("pat = %x\n",pat);
|
||||
//ee_printf("((i & 0x07) << 8) | pat = %x\n",((i & 0x07) << 8) | pat);
|
||||
//ee_printf("finder->info->idx = %d\n",finder->info->idx);
|
||||
}
|
||||
finder = finder->next;
|
||||
}
|
||||
list = core_list_mergesort(list, cmp_idx, NULL);
|
||||
|
||||
#if CORE_DEBUG
|
||||
ee_printf("Initialized list:\n");
|
||||
finder = list;
|
||||
while (finder)
|
||||
{
|
||||
ee_printf(
|
||||
"[%04x,%04x]", finder->info->idx, (ee_u16)finder->info->data16);
|
||||
finder = finder->next;
|
||||
}
|
||||
ee_printf("\n");
|
||||
#endif
|
||||
return list;
|
||||
}
|
||||
|
||||
/* Function: core_list_insert
|
||||
Insert an item to the list
|
||||
|
||||
Parameters:
|
||||
insert_point - where to insert the item.
|
||||
info - data for the cell.
|
||||
memblock - pointer for the list header
|
||||
datablock - pointer for the list data
|
||||
memblock_end - end of region for list headers
|
||||
datablock_end - end of region for list data
|
||||
|
||||
Returns:
|
||||
Pointer to new item.
|
||||
*/
|
||||
list_head *
|
||||
core_list_insert_new(list_head * insert_point,
|
||||
list_data * info,
|
||||
list_head **memblock,
|
||||
list_data **datablock,
|
||||
list_head * memblock_end,
|
||||
list_data * datablock_end)
|
||||
{
|
||||
list_head *newitem;
|
||||
|
||||
if ((*memblock + 1) >= memblock_end)
|
||||
return NULL;
|
||||
if ((*datablock + 1) >= datablock_end)
|
||||
return NULL;
|
||||
|
||||
newitem = *memblock;
|
||||
(*memblock)++;
|
||||
newitem->next = insert_point->next;
|
||||
insert_point->next = newitem;
|
||||
|
||||
newitem->info = *datablock;
|
||||
(*datablock)++;
|
||||
copy_info(newitem->info, info);
|
||||
|
||||
return newitem;
|
||||
}
|
||||
|
||||
/* Function: core_list_remove
|
||||
Remove an item from the list.
|
||||
|
||||
Operation:
|
||||
For a singly linked list, remove by copying the data from the next item
|
||||
over to the current cell, and unlinking the next item.
|
||||
|
||||
Note:
|
||||
since there is always a fake item at the end of the list, no need to
|
||||
check for NULL.
|
||||
|
||||
Returns:
|
||||
Removed item.
|
||||
*/
|
||||
list_head *
|
||||
core_list_remove(list_head *item)
|
||||
{
|
||||
list_data *tmp;
|
||||
list_head *ret = item->next;
|
||||
/* swap data pointers */
|
||||
tmp = item->info;
|
||||
item->info = ret->info;
|
||||
ret->info = tmp;
|
||||
/* and eliminate item */
|
||||
item->next = item->next->next;
|
||||
ret->next = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Function: core_list_undo_remove
|
||||
Undo a remove operation.
|
||||
|
||||
Operation:
|
||||
Since we want each iteration of the benchmark to be exactly the same,
|
||||
we need to be able to undo a remove.
|
||||
Link the removed item back into the list, and switch the info items.
|
||||
|
||||
Parameters:
|
||||
item_removed - Return value from the <core_list_remove>
|
||||
item_modified - List item that was modified during <core_list_remove>
|
||||
|
||||
Returns:
|
||||
The item that was linked back to the list.
|
||||
|
||||
*/
|
||||
list_head *
|
||||
core_list_undo_remove(list_head *item_removed, list_head *item_modified)
|
||||
{
|
||||
list_data *tmp;
|
||||
/* swap data pointers */
|
||||
tmp = item_removed->info;
|
||||
item_removed->info = item_modified->info;
|
||||
item_modified->info = tmp;
|
||||
/* and insert item */
|
||||
item_removed->next = item_modified->next;
|
||||
item_modified->next = item_removed;
|
||||
return item_removed;
|
||||
}
|
||||
|
||||
/* Function: core_list_find
|
||||
Find an item in the list
|
||||
|
||||
Operation:
|
||||
Find an item by idx (if not 0) or specific data value
|
||||
|
||||
Parameters:
|
||||
list - list head
|
||||
info - idx or data to find
|
||||
|
||||
Returns:
|
||||
Found item, or NULL if not found.
|
||||
*/
|
||||
list_head *
|
||||
core_list_find(list_head *list, list_data *info)
|
||||
{
|
||||
if (info->idx >= 0)
|
||||
{
|
||||
while (list && (list->info->idx != info->idx))
|
||||
list = list->next;
|
||||
return list;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (list && ((list->info->data16 & 0xff) != info->data16))
|
||||
list = list->next;
|
||||
return list;
|
||||
}
|
||||
}
|
||||
/* Function: core_list_reverse
|
||||
Reverse a list
|
||||
|
||||
Operation:
|
||||
Rearrange the pointers so the list is reversed.
|
||||
|
||||
Parameters:
|
||||
list - list head
|
||||
info - idx or data to find
|
||||
|
||||
Returns:
|
||||
Found item, or NULL if not found.
|
||||
*/
|
||||
|
||||
list_head *
|
||||
core_list_reverse(list_head *list)
|
||||
{
|
||||
list_head *next = NULL, *tmp;
|
||||
while (list)
|
||||
{
|
||||
tmp = list->next;
|
||||
list->next = next;
|
||||
next = list;
|
||||
list = tmp;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
/* Function: core_list_mergesort
|
||||
Sort the list in place without recursion.
|
||||
|
||||
Description:
|
||||
Use mergesort, as for linked list this is a realistic solution.
|
||||
Also, since this is aimed at embedded, care was taken to use iterative
|
||||
rather then recursive algorithm. The sort can either return the list to
|
||||
original order (by idx) , or use the data item to invoke other other
|
||||
algorithms and change the order of the list.
|
||||
|
||||
Parameters:
|
||||
list - list to be sorted.
|
||||
cmp - cmp function to use
|
||||
|
||||
Returns:
|
||||
New head of the list.
|
||||
|
||||
Note:
|
||||
We have a special header for the list that will always be first,
|
||||
but the algorithm could theoretically modify where the list starts.
|
||||
|
||||
*/
|
||||
list_head *
|
||||
core_list_mergesort(list_head *list, list_cmp cmp, core_results *res)
|
||||
{
|
||||
list_head *p, *q, *e, *tail;
|
||||
ee_s32 insize, nmerges, psize, qsize, i;
|
||||
|
||||
insize = 1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
p = list;
|
||||
list = NULL;
|
||||
tail = NULL;
|
||||
|
||||
nmerges = 0; /* count number of merges we do in this pass */
|
||||
|
||||
while (p)
|
||||
{
|
||||
nmerges++; /* there exists a merge to be done */
|
||||
/* step `insize' places along from p */
|
||||
q = p;
|
||||
psize = 0;
|
||||
for (i = 0; i < insize; i++)
|
||||
{
|
||||
psize++;
|
||||
q = q->next;
|
||||
if (!q)
|
||||
break;
|
||||
}
|
||||
|
||||
/* if q hasn't fallen off end, we have two lists to merge */
|
||||
qsize = insize;
|
||||
|
||||
/* now we have two lists; merge them */
|
||||
while (psize > 0 || (qsize > 0 && q))
|
||||
{
|
||||
|
||||
/* decide whether next element of merge comes from p or q */
|
||||
if (psize == 0)
|
||||
{
|
||||
/* p is empty; e must come from q. */
|
||||
e = q;
|
||||
q = q->next;
|
||||
qsize--;
|
||||
}
|
||||
else if (qsize == 0 || !q)
|
||||
{
|
||||
/* q is empty; e must come from p. */
|
||||
e = p;
|
||||
p = p->next;
|
||||
psize--;
|
||||
}
|
||||
else if (cmp(p->info, q->info, res) <= 0)
|
||||
{
|
||||
/* First element of p is lower (or same); e must come from
|
||||
* p. */
|
||||
e = p;
|
||||
p = p->next;
|
||||
psize--;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* First element of q is lower; e must come from q. */
|
||||
e = q;
|
||||
q = q->next;
|
||||
qsize--;
|
||||
}
|
||||
|
||||
/* add the next element to the merged list */
|
||||
if (tail)
|
||||
{
|
||||
tail->next = e;
|
||||
}
|
||||
else
|
||||
{
|
||||
list = e;
|
||||
}
|
||||
tail = e;
|
||||
}
|
||||
|
||||
/* now p has stepped `insize' places along, and q has too */
|
||||
p = q;
|
||||
}
|
||||
|
||||
tail->next = NULL;
|
||||
|
||||
/* If we have done only one merge, we're finished. */
|
||||
if (nmerges <= 1) /* allow for nmerges==0, the empty list case */
|
||||
return list;
|
||||
|
||||
/* Otherwise repeat, merging lists twice the size */
|
||||
insize *= 2;
|
||||
}
|
||||
#if COMPILER_REQUIRES_SORT_RETURN
|
||||
return list;
|
||||
#endif
|
||||
}
|
||||
422
sdk/software/examples/coremark/core_main.c
Normal file
422
sdk/software/examples/coremark/core_main.c
Normal file
@@ -0,0 +1,422 @@
|
||||
/*
|
||||
Author : Shay Gal-On, EEMBC
|
||||
|
||||
This file is part of EEMBC(R) and CoreMark(TM), which are Copyright (C) 2009
|
||||
All rights reserved.
|
||||
|
||||
EEMBC CoreMark Software is a product of EEMBC and is provided under the terms of the
|
||||
CoreMark License that is distributed with the official EEMBC COREMARK Software release.
|
||||
If you received this EEMBC CoreMark Software without the accompanying CoreMark License,
|
||||
you must discontinue use and download the official release from www.coremark.org.
|
||||
|
||||
Also, if you are publicly displaying scores generated from the EEMBC CoreMark software,
|
||||
make sure that you are in compliance with Run and Reporting rules specified in the accompanying readme.txt file.
|
||||
|
||||
EEMBC
|
||||
4354 Town Center Blvd. Suite 114-200
|
||||
El Dorado Hills, CA, 95762
|
||||
*/
|
||||
/* File: core_main.c
|
||||
This file contains the framework to acquire a block of memory, seed initial parameters, tun t he benchmark and report the results.
|
||||
*/
|
||||
#include "coremark.h"
|
||||
|
||||
/* Function: iterate
|
||||
Run the benchmark for a specified number of iterations.
|
||||
|
||||
Operation:
|
||||
For each type of benchmarked algorithm:
|
||||
a - Initialize the data block for the algorithm.
|
||||
b - Execute the algorithm N times.
|
||||
|
||||
Returns:
|
||||
NULL.
|
||||
*/
|
||||
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbf000000; //UART16550的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbf20f100; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 50000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
static ee_u16 list_known_crc[] = {(ee_u16)0xd4b0,(ee_u16)0x3340,(ee_u16)0x6a79,(ee_u16)0xe714,(ee_u16)0xe3c1};
|
||||
static ee_u16 matrix_known_crc[] = {(ee_u16)0xbe52,(ee_u16)0x1199,(ee_u16)0x5608,(ee_u16)0x1fd7,(ee_u16)0x0747};
|
||||
static ee_u16 state_known_crc[] = {(ee_u16)0x5e47,(ee_u16)0x39bf,(ee_u16)0xe5a4,(ee_u16)0x8e3a,(ee_u16)0x8d84};
|
||||
void *iterate(void *pres) {
|
||||
ee_u32 i;
|
||||
ee_u16 crc;
|
||||
core_results *res=(core_results *)pres;
|
||||
ee_u32 iterations=res->iterations;
|
||||
res->crc=0;
|
||||
res->crclist=0;
|
||||
res->crcmatrix=0;
|
||||
res->crcstate=0;
|
||||
|
||||
for (i=0; i<iterations; i++) {
|
||||
crc=core_bench_list(res,1);
|
||||
res->crc=crcu16(crc,res->crc);
|
||||
crc=core_bench_list(res,-1);
|
||||
res->crc=crcu16(crc,res->crc);
|
||||
if (i==0) res->crclist=res->crc;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if (SEED_METHOD==SEED_ARG)
|
||||
ee_s32 get_seed_args(int i, int argc, char *argv[]);
|
||||
#define get_seed(x) (ee_s16)get_seed_args(x,argc,argv)
|
||||
#define get_seed_32(x) get_seed_args(x,argc,argv)
|
||||
#else /* via function or volatile */
|
||||
ee_s32 get_seed_32(int i);
|
||||
#define get_seed(x) (ee_s16)get_seed_32(x)
|
||||
#endif
|
||||
|
||||
#if (MEM_METHOD==MEM_STATIC)
|
||||
ee_u8 static_memblk[TOTAL_DATA_SIZE];
|
||||
#endif
|
||||
char *mem_name[3] = {"Static","Heap","Stack"};
|
||||
/* Function: main
|
||||
Main entry routine for the benchmark.
|
||||
This function is responsible for the following steps:
|
||||
|
||||
1 - Initialize input seeds from a source that cannot be determined at compile time.
|
||||
2 - Initialize memory block for use.
|
||||
3 - Run and time the benchmark.
|
||||
4 - Report results, testing the validity of the output if the seeds are known.
|
||||
|
||||
Arguments:
|
||||
1 - first seed : Any value
|
||||
2 - second seed : Must be identical to first for iterations to be identical
|
||||
3 - third seed : Any value, should be at least an order of magnitude less then the input size, but bigger then 32.
|
||||
4 - Iterations : Special, if set to 0, iterations will be automatically determined such that the benchmark will run between 10 to 100 secs
|
||||
|
||||
*/
|
||||
|
||||
#if MAIN_HAS_NOARGC
|
||||
MAIN_RETURN_TYPE main(void) {
|
||||
int argc=0;
|
||||
char *argv[1];
|
||||
#else
|
||||
MAIN_RETURN_TYPE main(int argc, char *argv[]) {
|
||||
#endif
|
||||
ee_u16 i,j=0,num_algorithms=0;
|
||||
ee_s16 known_id=-1,total_errors=0;
|
||||
ee_u16 seedcrc=0;
|
||||
CORE_TICKS total_time;
|
||||
core_results results[MULTITHREAD];
|
||||
#if (MEM_METHOD==MEM_STACK)
|
||||
ee_u8 stack_memblock[TOTAL_DATA_SIZE*MULTITHREAD];
|
||||
#endif
|
||||
/* first call any initializations needed */
|
||||
//portable_init(&(results[0].port), &argc, argv);
|
||||
/* First some checks to make sure benchmark will run ok */
|
||||
if (sizeof(struct list_head_s)>128) {
|
||||
|
||||
return MAIN_RETURN_VAL;
|
||||
}
|
||||
results[0].seed1=get_seed(1);
|
||||
results[0].seed2=get_seed(2);
|
||||
results[0].seed3=get_seed(3);
|
||||
results[0].iterations=get_seed_32(4);
|
||||
#if CORE_DEBUG
|
||||
results[0].iterations=1;
|
||||
#endif
|
||||
// Bob: change the interation times to make it faster
|
||||
/* Initializations */
|
||||
// UART_INIT(UART, 3, CCLK, BAUD);
|
||||
|
||||
results[0].execs=get_seed_32(5);
|
||||
if (results[0].execs==0) { /* if not supplied, execute all algorithms */
|
||||
results[0].execs=ALL_ALGORITHMS_MASK;
|
||||
}
|
||||
/* put in some default values based on one seed only for easy testing */
|
||||
if ((results[0].seed1==0) && (results[0].seed2==0) && (results[0].seed3==0)) { /* validation run */
|
||||
results[0].seed1=0;
|
||||
results[0].seed2=0;
|
||||
results[0].seed3=0x66;
|
||||
}
|
||||
if ((results[0].seed1==1) && (results[0].seed2==0) && (results[0].seed3==0)) { /* perfromance run */
|
||||
results[0].seed1=0x3415;
|
||||
results[0].seed2=0x3415;
|
||||
results[0].seed3=0x66;
|
||||
}
|
||||
#if (MEM_METHOD==MEM_STATIC)
|
||||
results[0].memblock[0]=(void *)static_memblk;
|
||||
results[0].size=TOTAL_DATA_SIZE;
|
||||
results[0].err=0;
|
||||
#if (MULTITHREAD>1)
|
||||
#error "Cannot use a static data area with multiple contexts!"
|
||||
#endif
|
||||
#elif (MEM_METHOD==MEM_MALLOC)
|
||||
for (i=0 ; i<MULTITHREAD; i++) {
|
||||
ee_s32 malloc_override=get_seed(7);
|
||||
if (malloc_override != 0)
|
||||
results[i].size=malloc_override;
|
||||
else
|
||||
results[i].size=TOTAL_DATA_SIZE;
|
||||
results[i].memblock[0]=portable_malloc(results[i].size);
|
||||
results[i].seed1=results[0].seed1;
|
||||
results[i].seed2=results[0].seed2;
|
||||
results[i].seed3=results[0].seed3;
|
||||
results[i].err=0;
|
||||
results[i].execs=results[0].execs;
|
||||
}
|
||||
#elif (MEM_METHOD==MEM_STACK)
|
||||
for (i=0 ; i<MULTITHREAD; i++) {
|
||||
results[i].memblock[0]=stack_memblock+i*TOTAL_DATA_SIZE;
|
||||
results[i].size=TOTAL_DATA_SIZE;
|
||||
results[i].seed1=results[0].seed1;
|
||||
results[i].seed2=results[0].seed2;
|
||||
results[i].seed3=results[0].seed3;
|
||||
results[i].err=0;
|
||||
results[i].execs=results[0].execs;
|
||||
}
|
||||
#else
|
||||
#error "Please define a way to initialize a memory block."
|
||||
#endif
|
||||
// ee_printf("results[0].seed1 = %x\n",results[0].seed1);
|
||||
// ee_printf("results[0].seed2 = %x\n",results[0].seed2);
|
||||
// ee_printf("results[0].seed3 = %x\n",results[0].seed3);
|
||||
// ee_printf("results[0].size = %d\n",results[0].size);
|
||||
/* Data init */
|
||||
/* Find out how space much we have based on number of algorithms */
|
||||
for (i=0; i<NUM_ALGORITHMS; i++) {
|
||||
if ((1<<(ee_u32)i) & results[0].execs)
|
||||
num_algorithms++;
|
||||
}
|
||||
for (i=0 ; i<MULTITHREAD; i++)
|
||||
results[i].size=results[i].size/num_algorithms;
|
||||
/* Assign pointers */
|
||||
for (i=0; i<NUM_ALGORITHMS; i++) {
|
||||
ee_u32 ctx;
|
||||
if ((1<<(ee_u32)i) & results[0].execs) {
|
||||
for (ctx=0 ; ctx<MULTITHREAD; ctx++)
|
||||
results[ctx].memblock[i+1]=(char *)(results[ctx].memblock[0])+results[0].size*j;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
/* call inits */
|
||||
for (i=0 ; i<MULTITHREAD; i++) {
|
||||
if (results[i].execs & ID_LIST) {
|
||||
results[i].list=core_list_init(results[0].size,results[i].memblock[1],results[i].seed1);
|
||||
}
|
||||
if (results[i].execs & ID_MATRIX) {
|
||||
core_init_matrix(results[0].size, results[i].memblock[2], (ee_s32)results[i].seed1 | (((ee_s32)results[i].seed2) << 16), &(results[i].mat) );
|
||||
}
|
||||
if (results[i].execs & ID_STATE) {
|
||||
core_init_state(results[0].size,results[i].seed1,results[i].memblock[3]);
|
||||
}
|
||||
}
|
||||
|
||||
/* perform actual benchmark */
|
||||
unsigned int cycle1,cycle2;
|
||||
// asm volatile(
|
||||
// "rdcntvl.w %0\n\t"
|
||||
// :"=r"(cycle1)
|
||||
// );
|
||||
// asm volatile(
|
||||
// "li.w $r25, 0xbfafe000\n\t"
|
||||
// "ld.w %0,$r25,0\n\t"
|
||||
// :"=r"(cycle1)
|
||||
// :
|
||||
// :"$r25"
|
||||
// );
|
||||
// cycle1 = get_clock_count();
|
||||
start_time();
|
||||
#if (MULTITHREAD>1)
|
||||
if (default_num_contexts>MULTITHREAD) {
|
||||
default_num_contexts=MULTITHREAD;
|
||||
}
|
||||
for (i=0 ; i<default_num_contexts; i++) {
|
||||
results[i].iterations=results[0].iterations;
|
||||
results[i].execs=results[0].execs;
|
||||
core_start_parallel(&results[i]);
|
||||
}
|
||||
for (i=0 ; i<default_num_contexts; i++) {
|
||||
core_stop_parallel(&results[i]);
|
||||
}
|
||||
#else
|
||||
iterate(&results[0]);
|
||||
#endif
|
||||
stop_time();
|
||||
total_time = get_time();
|
||||
// total_time = get_time();
|
||||
// asm volatile(
|
||||
// "rdcntvl.w %0\n\t"
|
||||
// :"=r"(cycle2)
|
||||
// );
|
||||
// asm volatile(
|
||||
// "li.w $r25, 0xbfafe000\n\t"
|
||||
// "ld.w %0,$r25,0\n\t"
|
||||
// :"=r"(cycle2)
|
||||
// :
|
||||
// :"$r25"
|
||||
// );
|
||||
// cycle2 = get_clock_count();
|
||||
// total_time = (uint64_t)(cycle2 - cycle1);
|
||||
|
||||
/* get a function of the input to report */
|
||||
seedcrc=crc16(results[0].seed1,seedcrc);
|
||||
seedcrc=crc16(results[0].seed2,seedcrc);
|
||||
seedcrc=crc16(results[0].seed3,seedcrc);
|
||||
seedcrc=crc16(results[0].size,seedcrc);
|
||||
switch (seedcrc)
|
||||
{ /* test known output for common seeds */
|
||||
case 0x8a02: /* seed1=0, seed2=0, seed3=0x66, size 2000 per algorithm */
|
||||
known_id = 0;
|
||||
ee_printf("6k performance run parameters for coremark.\n");
|
||||
break;
|
||||
case 0x7b05: /* seed1=0x3415, seed2=0x3415, seed3=0x66, size 2000 per
|
||||
algorithm */
|
||||
known_id = 1;
|
||||
ee_printf("6k validation run parameters for coremark.\n");
|
||||
break;
|
||||
case 0x4eaf: /* seed1=0x8, seed2=0x8, seed3=0x8, size 400 per algorithm
|
||||
*/
|
||||
known_id = 2;
|
||||
ee_printf("Profile generation run parameters for coremark.\n");
|
||||
break;
|
||||
case 0xe9f5: /* seed1=0, seed2=0, seed3=0x66, size 666 per algorithm */
|
||||
known_id = 3;
|
||||
ee_printf("2K performance run parameters for coremark.\n");
|
||||
break;
|
||||
case 0x18f2: /* seed1=0x3415, seed2=0x3415, seed3=0x66, size 666 per
|
||||
algorithm */
|
||||
known_id = 4;
|
||||
ee_printf("2K validation run parameters for coremark.\n");
|
||||
break;
|
||||
default:
|
||||
total_errors = -1;
|
||||
break;
|
||||
}
|
||||
if (known_id >= 0)
|
||||
{
|
||||
for (i = 0; i < default_num_contexts; i++)
|
||||
{
|
||||
results[i].err = 0;
|
||||
if ((results[i].execs & ID_LIST)
|
||||
&& (results[i].crclist != list_known_crc[known_id]))
|
||||
{
|
||||
ee_printf("[%u]ERROR! list crc 0x%04x - should be 0x%04x\n",
|
||||
i,
|
||||
results[i].crclist,
|
||||
list_known_crc[known_id]);
|
||||
results[i].err++;
|
||||
}
|
||||
if ((results[i].execs & ID_MATRIX)
|
||||
&& (results[i].crcmatrix != matrix_known_crc[known_id]))
|
||||
{
|
||||
ee_printf("[%u]ERROR! matrix crc 0x%04x - should be 0x%04x\n",
|
||||
i,
|
||||
results[i].crcmatrix,
|
||||
matrix_known_crc[known_id]);
|
||||
results[i].err++;
|
||||
}
|
||||
if ((results[i].execs & ID_STATE)
|
||||
&& (results[i].crcstate != state_known_crc[known_id]))
|
||||
{
|
||||
ee_printf("[%u]ERROR! state crc 0x%04x - should be 0x%04x\n",
|
||||
i,
|
||||
results[i].crcstate,
|
||||
state_known_crc[known_id]);
|
||||
results[i].err++;
|
||||
}
|
||||
total_errors += results[i].err;
|
||||
}
|
||||
}
|
||||
total_errors += check_data_types();
|
||||
|
||||
/* and report results */
|
||||
ee_printf("CoreMark Size : %lu\n", (long unsigned)results[0].size);
|
||||
ee_printf("Total ticks : %lu\n", (long unsigned)total_time);
|
||||
#if HAS_FLOAT
|
||||
ee_printf("Total time (secs): %f\n", time_in_secs(total_time));
|
||||
if (time_in_secs(total_time) > 0)
|
||||
ee_printf("Iterations/Sec : %f\n",
|
||||
default_num_contexts * results[0].iterations
|
||||
/ time_in_secs(total_time));
|
||||
#else
|
||||
ee_printf("Total time (secs): %d\n", time_in_secs(total_time));
|
||||
if (time_in_secs(total_time) > 0)
|
||||
ee_printf("Iterations/Sec : %d\n",
|
||||
default_num_contexts * results[0].iterations
|
||||
/ time_in_secs(total_time));
|
||||
#endif
|
||||
// if (time_in_secs(total_time) < 10)
|
||||
// {
|
||||
// ee_printf(
|
||||
// "ERROR! Must execute for at least 10 secs for a valid result!\n");
|
||||
// total_errors++;
|
||||
// }
|
||||
|
||||
ee_printf("Iterations : %lu\n",
|
||||
(long unsigned)default_num_contexts * results[0].iterations);
|
||||
ee_printf("Compiler version : %s\n", COMPILER_VERSION);
|
||||
ee_printf("Compiler flags : %s\n", COMPILER_FLAGS);
|
||||
#if (MULTITHREAD > 1)
|
||||
ee_printf("Parallel %s : %d\n", PARALLEL_METHOD, default_num_contexts);
|
||||
#endif
|
||||
ee_printf("Memory location : %s\n", MEM_LOCATION);
|
||||
/* output for verification */
|
||||
ee_printf("seedcrc : 0x%04x\n", seedcrc);
|
||||
if (results[0].execs & ID_LIST)
|
||||
for (i = 0; i < default_num_contexts; i++)
|
||||
ee_printf("[%d]crclist : 0x%04x\n", i, results[i].crclist);
|
||||
if (results[0].execs & ID_MATRIX)
|
||||
for (i = 0; i < default_num_contexts; i++)
|
||||
ee_printf("[%d]crcmatrix : 0x%04x\n", i, results[i].crcmatrix);
|
||||
if (results[0].execs & ID_STATE)
|
||||
for (i = 0; i < default_num_contexts; i++)
|
||||
ee_printf("[%d]crcstate : 0x%04x\n", i, results[i].crcstate);
|
||||
for (i = 0; i < default_num_contexts; i++)
|
||||
ee_printf("[%d]crcfinal : 0x%04x\n", i, results[i].crc);
|
||||
if (total_errors == 0)
|
||||
{
|
||||
ee_printf(
|
||||
"Correct operation validated. See README.md for run and reporting "
|
||||
"rules.\n");
|
||||
#if HAS_FLOAT
|
||||
if (known_id == 3)
|
||||
{
|
||||
ee_printf("CoreMark 1.0 : %f / %s %s",
|
||||
default_num_contexts * results[0].iterations
|
||||
/ time_in_secs(total_time),
|
||||
COMPILER_VERSION,
|
||||
COMPILER_FLAGS);
|
||||
#if defined(MEM_LOCATION) && !defined(MEM_LOCATION_UNSPEC)
|
||||
ee_printf(" / %s", MEM_LOCATION);
|
||||
#else
|
||||
ee_printf(" / %s", mem_name[MEM_METHOD]);
|
||||
#endif
|
||||
|
||||
#if (MULTITHREAD > 1)
|
||||
ee_printf(" / %d:%s", default_num_contexts, PARALLEL_METHOD);
|
||||
#endif
|
||||
ee_printf("\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (total_errors > 0)
|
||||
ee_printf("Errors detected\n");
|
||||
if (total_errors < 0)
|
||||
ee_printf(
|
||||
"Cannot validate operation for these seed values, please compare "
|
||||
"with results on a known platform.\n");
|
||||
|
||||
float coremark_dmips = (results[0].iterations*1000000)/(float)total_time;
|
||||
#if HAS_FLOAT
|
||||
ee_printf ("\n");
|
||||
ee_printf ("\n");
|
||||
ee_printf ("Print Personal Added Addtional Info to Easy Visual Analysis\n");
|
||||
ee_printf ("\n");
|
||||
ee_printf (" (*) Assume the core running at %d MHz\n",CORE_CLOCKS_PER_SEC/1000000);
|
||||
ee_printf (" So the CoreMark/MHz can be caculated by: \n");
|
||||
ee_printf (" (Iterations*1000000/total_ticks) = %2.6f CoreMark/MHz\n", coremark_dmips);
|
||||
ee_printf ("\n");
|
||||
#endif
|
||||
|
||||
return MAIN_RETURN_VAL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
359
sdk/software/examples/coremark/core_matrix.c
Normal file
359
sdk/software/examples/coremark/core_matrix.c
Normal file
@@ -0,0 +1,359 @@
|
||||
/*
|
||||
Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Original Author: Shay Gal-on
|
||||
*/
|
||||
|
||||
#include "coremark.h"
|
||||
/*
|
||||
Topic: Description
|
||||
Matrix manipulation benchmark
|
||||
|
||||
This very simple algorithm forms the basis of many more complex
|
||||
algorithms.
|
||||
|
||||
The tight inner loop is the focus of many optimizations (compiler as
|
||||
well as hardware based) and is thus relevant for embedded processing.
|
||||
|
||||
The total available data space will be divided to 3 parts:
|
||||
NxN Matrix A - initialized with small values (upper 3/4 of the bits all
|
||||
zero). NxN Matrix B - initialized with medium values (upper half of the bits all
|
||||
zero). NxN Matrix C - used for the result.
|
||||
|
||||
The actual values for A and B must be derived based on input that is not
|
||||
available at compile time.
|
||||
*/
|
||||
ee_s16 matrix_test(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B, MATDAT val);
|
||||
ee_s16 matrix_sum(ee_u32 N, MATRES *C, MATDAT clipval);
|
||||
void matrix_mul_const(ee_u32 N, MATRES *C, MATDAT *A, MATDAT val);
|
||||
void matrix_mul_vect(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B);
|
||||
void matrix_mul_matrix(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B);
|
||||
void matrix_mul_matrix_bitextract(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B);
|
||||
void matrix_add_const(ee_u32 N, MATDAT *A, MATDAT val);
|
||||
|
||||
#define matrix_test_next(x) (x + 1)
|
||||
#define matrix_clip(x, y) ((y) ? (x)&0x0ff : (x)&0x0ffff)
|
||||
#define matrix_big(x) (0xf000 | (x))
|
||||
#define bit_extract(x, from, to) (((x) >> (from)) & (~(0xffffffff << (to))))
|
||||
|
||||
#if CORE_DEBUG
|
||||
void
|
||||
printmat(MATDAT *A, ee_u32 N, char *name)
|
||||
{
|
||||
ee_u32 i, j;
|
||||
ee_printf("Matrix %s [%dx%d]:\n", name, N, N);
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
for (j = 0; j < N; j++)
|
||||
{
|
||||
if (j != 0)
|
||||
ee_printf(",");
|
||||
ee_printf("%d", A[i * N + j]);
|
||||
}
|
||||
ee_printf("\n");
|
||||
}
|
||||
}
|
||||
void
|
||||
printmatC(MATRES *C, ee_u32 N, char *name)
|
||||
{
|
||||
ee_u32 i, j;
|
||||
ee_printf("Matrix %s [%dx%d]:\n", name, N, N);
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
for (j = 0; j < N; j++)
|
||||
{
|
||||
if (j != 0)
|
||||
ee_printf(",");
|
||||
ee_printf("%d", C[i * N + j]);
|
||||
}
|
||||
ee_printf("\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Function: core_bench_matrix
|
||||
Benchmark function
|
||||
|
||||
Iterate <matrix_test> N times,
|
||||
changing the matrix values slightly by a constant amount each time.
|
||||
*/
|
||||
ee_u16
|
||||
core_bench_matrix(mat_params *p, ee_s16 seed, ee_u16 crc)
|
||||
{
|
||||
ee_u32 N = p->N;
|
||||
MATRES *C = p->C;
|
||||
MATDAT *A = p->A;
|
||||
MATDAT *B = p->B;
|
||||
MATDAT val = (MATDAT)seed;
|
||||
|
||||
crc = crc16(matrix_test(N, C, A, B, val), crc);
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
/* Function: matrix_test
|
||||
Perform matrix manipulation.
|
||||
|
||||
Parameters:
|
||||
N - Dimensions of the matrix.
|
||||
C - memory for result matrix.
|
||||
A - input matrix
|
||||
B - operator matrix (not changed during operations)
|
||||
|
||||
Returns:
|
||||
A CRC value that captures all results calculated in the function.
|
||||
In particular, crc of the value calculated on the result matrix
|
||||
after each step by <matrix_sum>.
|
||||
|
||||
Operation:
|
||||
|
||||
1 - Add a constant value to all elements of a matrix.
|
||||
2 - Multiply a matrix by a constant.
|
||||
3 - Multiply a matrix by a vector.
|
||||
4 - Multiply a matrix by a matrix.
|
||||
5 - Add a constant value to all elements of a matrix.
|
||||
|
||||
After the last step, matrix A is back to original contents.
|
||||
*/
|
||||
ee_s16
|
||||
matrix_test(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B, MATDAT val)
|
||||
{
|
||||
ee_u16 crc = 0;
|
||||
MATDAT clipval = matrix_big(val);
|
||||
|
||||
matrix_add_const(N, A, val); /* make sure data changes */
|
||||
#if CORE_DEBUG
|
||||
printmat(A, N, "matrix_add_const");
|
||||
#endif
|
||||
matrix_mul_const(N, C, A, val);
|
||||
crc = crc16(matrix_sum(N, C, clipval), crc);
|
||||
#if CORE_DEBUG
|
||||
printmatC(C, N, "matrix_mul_const");
|
||||
#endif
|
||||
matrix_mul_vect(N, C, A, B);
|
||||
crc = crc16(matrix_sum(N, C, clipval), crc);
|
||||
#if CORE_DEBUG
|
||||
printmatC(C, N, "matrix_mul_vect");
|
||||
#endif
|
||||
matrix_mul_matrix(N, C, A, B);
|
||||
crc = crc16(matrix_sum(N, C, clipval), crc);
|
||||
#if CORE_DEBUG
|
||||
printmatC(C, N, "matrix_mul_matrix");
|
||||
#endif
|
||||
matrix_mul_matrix_bitextract(N, C, A, B);
|
||||
crc = crc16(matrix_sum(N, C, clipval), crc);
|
||||
#if CORE_DEBUG
|
||||
printmatC(C, N, "matrix_mul_matrix_bitextract");
|
||||
#endif
|
||||
|
||||
matrix_add_const(N, A, -val); /* return matrix to initial value */
|
||||
return crc;
|
||||
}
|
||||
|
||||
/* Function : matrix_init
|
||||
Initialize the memory block for matrix benchmarking.
|
||||
|
||||
Parameters:
|
||||
blksize - Size of memory to be initialized.
|
||||
memblk - Pointer to memory block.
|
||||
seed - Actual values chosen depend on the seed parameter.
|
||||
p - pointers to <mat_params> containing initialized matrixes.
|
||||
|
||||
Returns:
|
||||
Matrix dimensions.
|
||||
|
||||
Note:
|
||||
The seed parameter MUST be supplied from a source that cannot be
|
||||
determined at compile time
|
||||
*/
|
||||
ee_u32
|
||||
core_init_matrix(ee_u32 blksize, void *memblk, ee_s32 seed, mat_params *p)
|
||||
{
|
||||
ee_u32 N = 0;
|
||||
MATDAT *A;
|
||||
MATDAT *B;
|
||||
ee_s32 order = 1;
|
||||
MATDAT val;
|
||||
ee_u32 i = 0, j = 0;
|
||||
if (seed == 0)
|
||||
seed = 1;
|
||||
while (j < blksize)
|
||||
{
|
||||
i++;
|
||||
j = i * i * 2 * 4;
|
||||
}
|
||||
N = i - 1;
|
||||
A = (MATDAT *)align_mem(memblk);
|
||||
B = A + N * N;
|
||||
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
for (j = 0; j < N; j++)
|
||||
{
|
||||
seed = ((order * seed) % 65536);
|
||||
val = (seed + order);
|
||||
val = matrix_clip(val, 0);
|
||||
B[i * N + j] = val;
|
||||
val = (val + order);
|
||||
val = matrix_clip(val, 1);
|
||||
A[i * N + j] = val;
|
||||
order++;
|
||||
}
|
||||
}
|
||||
|
||||
p->A = A;
|
||||
p->B = B;
|
||||
p->C = (MATRES *)align_mem(B + N * N);
|
||||
p->N = N;
|
||||
#if CORE_DEBUG
|
||||
printmat(A, N, "A");
|
||||
printmat(B, N, "B");
|
||||
#endif
|
||||
return N;
|
||||
}
|
||||
|
||||
/* Function: matrix_sum
|
||||
Calculate a function that depends on the values of elements in the
|
||||
matrix.
|
||||
|
||||
For each element, accumulate into a temporary variable.
|
||||
|
||||
As long as this value is under the parameter clipval,
|
||||
add 1 to the result if the element is bigger then the previous.
|
||||
|
||||
Otherwise, reset the accumulator and add 10 to the result.
|
||||
*/
|
||||
ee_s16
|
||||
matrix_sum(ee_u32 N, MATRES *C, MATDAT clipval)
|
||||
{
|
||||
MATRES tmp = 0, prev = 0, cur = 0;
|
||||
ee_s16 ret = 0;
|
||||
ee_u32 i, j;
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
for (j = 0; j < N; j++)
|
||||
{
|
||||
cur = C[i * N + j];
|
||||
tmp += cur;
|
||||
if (tmp > clipval)
|
||||
{
|
||||
ret += 10;
|
||||
tmp = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret += (cur > prev) ? 1 : 0;
|
||||
}
|
||||
prev = cur;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Function: matrix_mul_const
|
||||
Multiply a matrix by a constant.
|
||||
This could be used as a scaler for instance.
|
||||
*/
|
||||
void
|
||||
matrix_mul_const(ee_u32 N, MATRES *C, MATDAT *A, MATDAT val)
|
||||
{
|
||||
ee_u32 i, j;
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
for (j = 0; j < N; j++)
|
||||
{
|
||||
C[i * N + j] = (MATRES)A[i * N + j] * (MATRES)val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Function: matrix_add_const
|
||||
Add a constant value to all elements of a matrix.
|
||||
*/
|
||||
void
|
||||
matrix_add_const(ee_u32 N, MATDAT *A, MATDAT val)
|
||||
{
|
||||
ee_u32 i, j;
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
for (j = 0; j < N; j++)
|
||||
{
|
||||
A[i * N + j] += val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Function: matrix_mul_vect
|
||||
Multiply a matrix by a vector.
|
||||
This is common in many simple filters (e.g. fir where a vector of
|
||||
coefficients is applied to the matrix.)
|
||||
*/
|
||||
void
|
||||
matrix_mul_vect(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B)
|
||||
{
|
||||
ee_u32 i, j;
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
C[i] = 0;
|
||||
for (j = 0; j < N; j++)
|
||||
{
|
||||
C[i] += (MATRES)A[i * N + j] * (MATRES)B[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Function: matrix_mul_matrix
|
||||
Multiply a matrix by a matrix.
|
||||
Basic code is used in many algorithms, mostly with minor changes such as
|
||||
scaling.
|
||||
*/
|
||||
void
|
||||
matrix_mul_matrix(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B)
|
||||
{
|
||||
ee_u32 i, j, k;
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
for (j = 0; j < N; j++)
|
||||
{
|
||||
C[i * N + j] = 0;
|
||||
for (k = 0; k < N; k++)
|
||||
{
|
||||
C[i * N + j] += (MATRES)A[i * N + k] * (MATRES)B[k * N + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Function: matrix_mul_matrix_bitextract
|
||||
Multiply a matrix by a matrix, and extract some bits from the result.
|
||||
Basic code is used in many algorithms, mostly with minor changes such as
|
||||
scaling.
|
||||
*/
|
||||
void
|
||||
matrix_mul_matrix_bitextract(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B)
|
||||
{
|
||||
ee_u32 i, j, k;
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
for (j = 0; j < N; j++)
|
||||
{
|
||||
C[i * N + j] = 0;
|
||||
for (k = 0; k < N; k++)
|
||||
{
|
||||
MATRES tmp = (MATRES)A[i * N + k] * (MATRES)B[k * N + j];
|
||||
C[i * N + j] += bit_extract(tmp, 2, 4) * bit_extract(tmp, 5, 7);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
53
sdk/software/examples/coremark/core_portme.c
Normal file
53
sdk/software/examples/coremark/core_portme.c
Normal file
@@ -0,0 +1,53 @@
|
||||
//#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
#include "coremark.h"
|
||||
//#include "platform.h"
|
||||
//#include "encoding.h"
|
||||
|
||||
#if VALIDATION_RUN
|
||||
volatile ee_s32 seed1_volatile=0x3415;
|
||||
volatile ee_s32 seed2_volatile=0x3415;
|
||||
volatile ee_s32 seed3_volatile=0x66;
|
||||
#endif
|
||||
|
||||
#if PERFORMANCE_RUN
|
||||
volatile ee_s32 seed1_volatile=0x0;
|
||||
volatile ee_s32 seed2_volatile=0x0;
|
||||
volatile ee_s32 seed3_volatile=0x66;
|
||||
#endif
|
||||
|
||||
#if PROFILE_RUN
|
||||
volatile ee_s32 seed1_volatile=0x8;
|
||||
volatile ee_s32 seed2_volatile=0x8;
|
||||
volatile ee_s32 seed3_volatile=0x8;
|
||||
#endif
|
||||
|
||||
volatile ee_s32 seed4_volatile=ITERATIONS;
|
||||
volatile ee_s32 seed5_volatile=0;
|
||||
|
||||
static CORE_TICKS t0, t1;
|
||||
|
||||
void start_time(void)
|
||||
{
|
||||
t0 = get_clock_count();
|
||||
}
|
||||
|
||||
void stop_time(void)
|
||||
{
|
||||
t1 = get_clock_count();
|
||||
}
|
||||
|
||||
CORE_TICKS get_time(void)
|
||||
{
|
||||
return t1 - t0;
|
||||
}
|
||||
|
||||
secs_ret time_in_secs(CORE_TICKS ticks)
|
||||
{
|
||||
#ifdef USE_CPU_CLOCK_COUNT
|
||||
secs_ret retval = ((secs_ret)ticks) / (secs_ret)CORE_CLOCKS_PER_SEC;
|
||||
#else
|
||||
secs_ret retval = ((secs_ret)ticks) / (secs_ret)CONFREG_CLOCKS_PER_SEC;
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
64
sdk/software/examples/coremark/core_portme.h
Normal file
64
sdk/software/examples/coremark/core_portme.h
Normal file
@@ -0,0 +1,64 @@
|
||||
//Bob: put some macro here such that the IDE SDK do not need to specify the macro specially
|
||||
// #define FLAGS_STR "-O3 -fno-common -funroll-all-loops -finline-limit=600 -ftree-dominator-opts -fno-if-conversion2 -fselective-scheduling -fno-code-hoisting --param max-inline-insns-auto=20 -falign-functions=4 -falign-jumps=4 -falign-loops=4"
|
||||
#define PERFORMANCE_RUN 1
|
||||
|
||||
#ifndef FESDK_CORE_PORTME_H
|
||||
#define FESDK_CORE_PORTME_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "confreg_time.h"
|
||||
|
||||
//#define CORE_DEBUG 1
|
||||
#define HAS_FLOAT 1
|
||||
#define HAS_TIME_H 1
|
||||
#define USE_CLOCK 1
|
||||
#define HAS_STDIO 1
|
||||
#define HAS_PRINTF 1
|
||||
#define SEED_METHOD SEED_VOLATILE
|
||||
#define CORE_TICKS uint64_t
|
||||
#define ee_u8 uint8_t
|
||||
#define ee_u16 uint16_t
|
||||
#define ee_u32 uint32_t
|
||||
#define ee_s16 int16_t
|
||||
#define ee_s32 int32_t
|
||||
#define ee_ptr_int uintptr_t
|
||||
#define ee_size_t size_t
|
||||
#define COMPILER_FLAGS FLAGS_STR
|
||||
|
||||
#define align_mem(x) (void *)(((ee_ptr_int)(x) + sizeof(ee_u32) - 1) & -sizeof(ee_u32))
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define COMPILER_VERSION "GCC8.3.0"
|
||||
#else
|
||||
# error
|
||||
#endif
|
||||
|
||||
#define MEM_METHOD MEM_STACK
|
||||
#define MEM_LOCATION "STACK"
|
||||
|
||||
#define MAIN_HAS_NOARGC 0
|
||||
#define MAIN_HAS_NORETURN 0
|
||||
|
||||
#define MULTITHREAD 1
|
||||
#define USE_PTHREAD 0
|
||||
#define USE_FORK 0
|
||||
#define USE_SOCKET 0
|
||||
|
||||
#define default_num_contexts MULTITHREAD
|
||||
|
||||
typedef int core_portable;
|
||||
//static void portable_init(core_portable *p, int *argc, char *argv[]) {}
|
||||
//static void portable_fini(core_portable *p) {}
|
||||
|
||||
#if !defined(PROFILE_RUN) && !defined(PERFORMANCE_RUN) && !defined(VALIDATION_RUN)
|
||||
#if (TOTAL_DATA_SIZE==1200)
|
||||
#define PROFILE_RUN 1
|
||||
#elif (TOTAL_DATA_SIZE==2000)
|
||||
#define PERFORMANCE_RUN 1
|
||||
#else
|
||||
#define VALIDATION_RUN 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
330
sdk/software/examples/coremark/core_state.c
Normal file
330
sdk/software/examples/coremark/core_state.c
Normal file
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Original Author: Shay Gal-on
|
||||
*/
|
||||
|
||||
#include "coremark.h"
|
||||
/* local functions */
|
||||
enum CORE_STATE core_state_transition(ee_u8 **instr, ee_u32 *transition_count);
|
||||
|
||||
/*
|
||||
Topic: Description
|
||||
Simple state machines like this one are used in many embedded products.
|
||||
|
||||
For more complex state machines, sometimes a state transition table
|
||||
implementation is used instead, trading speed of direct coding for ease of
|
||||
maintenance.
|
||||
|
||||
Since the main goal of using a state machine in CoreMark is to excercise
|
||||
the switch/if behaviour, we are using a small moore machine.
|
||||
|
||||
In particular, this machine tests type of string input,
|
||||
trying to determine whether the input is a number or something else.
|
||||
(see core_state.png).
|
||||
*/
|
||||
|
||||
/* Function: core_bench_state
|
||||
Benchmark function
|
||||
|
||||
Go over the input twice, once direct, and once after introducing some
|
||||
corruption.
|
||||
*/
|
||||
ee_u16
|
||||
core_bench_state(ee_u32 blksize,
|
||||
ee_u8 *memblock,
|
||||
ee_s16 seed1,
|
||||
ee_s16 seed2,
|
||||
ee_s16 step,
|
||||
ee_u16 crc)
|
||||
{
|
||||
ee_u32 final_counts[NUM_CORE_STATES];
|
||||
ee_u32 track_counts[NUM_CORE_STATES];
|
||||
ee_u8 *p = memblock;
|
||||
ee_u32 i;
|
||||
|
||||
#if CORE_DEBUG
|
||||
ee_printf("State Bench: %d,%d,%d,%04x\n", seed1, seed2, step, crc);
|
||||
#endif
|
||||
for (i = 0; i < NUM_CORE_STATES; i++)
|
||||
{
|
||||
final_counts[i] = track_counts[i] = 0;
|
||||
}
|
||||
/* run the state machine over the input */
|
||||
while (*p != 0)
|
||||
{
|
||||
enum CORE_STATE fstate = core_state_transition(&p, track_counts);
|
||||
final_counts[fstate]++;
|
||||
#if CORE_DEBUG
|
||||
ee_printf("%d,", fstate);
|
||||
}
|
||||
ee_printf("\n");
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
p = memblock;
|
||||
while (p < (memblock + blksize))
|
||||
{ /* insert some corruption */
|
||||
if (*p != ',')
|
||||
*p ^= (ee_u8)seed1;
|
||||
p += step;
|
||||
}
|
||||
p = memblock;
|
||||
/* run the state machine over the input again */
|
||||
while (*p != 0)
|
||||
{
|
||||
enum CORE_STATE fstate = core_state_transition(&p, track_counts);
|
||||
final_counts[fstate]++;
|
||||
#if CORE_DEBUG
|
||||
ee_printf("%d,", fstate);
|
||||
}
|
||||
ee_printf("\n");
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
p = memblock;
|
||||
while (p < (memblock + blksize))
|
||||
{ /* undo corruption is seed1 and seed2 are equal */
|
||||
if (*p != ',')
|
||||
*p ^= (ee_u8)seed2;
|
||||
p += step;
|
||||
}
|
||||
/* end timing */
|
||||
for (i = 0; i < NUM_CORE_STATES; i++)
|
||||
{
|
||||
crc = crcu32(final_counts[i], crc);
|
||||
crc = crcu32(track_counts[i], crc);
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
/* Default initialization patterns */
|
||||
static ee_u8 *intpat[4]
|
||||
= { (ee_u8 *)"5012", (ee_u8 *)"1234", (ee_u8 *)"-874", (ee_u8 *)"+122" };
|
||||
static ee_u8 *floatpat[4] = { (ee_u8 *)"35.54400",
|
||||
(ee_u8 *)".1234500",
|
||||
(ee_u8 *)"-110.700",
|
||||
(ee_u8 *)"+0.64400" };
|
||||
static ee_u8 *scipat[4] = { (ee_u8 *)"5.500e+3",
|
||||
(ee_u8 *)"-.123e-2",
|
||||
(ee_u8 *)"-87e+832",
|
||||
(ee_u8 *)"+0.6e-12" };
|
||||
static ee_u8 *errpat[4] = { (ee_u8 *)"T0.3e-1F",
|
||||
(ee_u8 *)"-T.T++Tq",
|
||||
(ee_u8 *)"1T3.4e4z",
|
||||
(ee_u8 *)"34.0e-T^" };
|
||||
|
||||
/* Function: core_init_state
|
||||
Initialize the input data for the state machine.
|
||||
|
||||
Populate the input with several predetermined strings, interspersed.
|
||||
Actual patterns chosen depend on the seed parameter.
|
||||
|
||||
Note:
|
||||
The seed parameter MUST be supplied from a source that cannot be
|
||||
determined at compile time
|
||||
*/
|
||||
void
|
||||
core_init_state(ee_u32 size, ee_s16 seed, ee_u8 *p)
|
||||
{
|
||||
ee_u32 total = 0, next = 0, i;
|
||||
ee_u8 *buf = 0;
|
||||
#if CORE_DEBUG
|
||||
ee_u8 *start = p;
|
||||
ee_printf("State: %d,%d\n", size, seed);
|
||||
#endif
|
||||
size--;
|
||||
next = 0;
|
||||
while ((total + next + 1) < size)
|
||||
{
|
||||
if (next > 0)
|
||||
{
|
||||
for (i = 0; i < next; i++)
|
||||
*(p + total + i) = buf[i];
|
||||
*(p + total + i) = ',';
|
||||
total += next + 1;
|
||||
}
|
||||
seed++;
|
||||
switch (seed & 0x7)
|
||||
{
|
||||
case 0: /* int */
|
||||
case 1: /* int */
|
||||
case 2: /* int */
|
||||
buf = intpat[(seed >> 3) & 0x3];
|
||||
next = 4;
|
||||
break;
|
||||
case 3: /* float */
|
||||
case 4: /* float */
|
||||
buf = floatpat[(seed >> 3) & 0x3];
|
||||
next = 8;
|
||||
break;
|
||||
case 5: /* scientific */
|
||||
case 6: /* scientific */
|
||||
buf = scipat[(seed >> 3) & 0x3];
|
||||
next = 8;
|
||||
break;
|
||||
case 7: /* invalid */
|
||||
buf = errpat[(seed >> 3) & 0x3];
|
||||
next = 8;
|
||||
break;
|
||||
default: /* Never happen, just to make some compilers happy */
|
||||
break;
|
||||
}
|
||||
}
|
||||
size++;
|
||||
while (total < size)
|
||||
{ /* fill the rest with 0 */
|
||||
*(p + total) = 0;
|
||||
total++;
|
||||
}
|
||||
#if CORE_DEBUG
|
||||
ee_printf("State Input: %s\n", start);
|
||||
#endif
|
||||
}
|
||||
|
||||
static ee_u8
|
||||
ee_isdigit(ee_u8 c)
|
||||
{
|
||||
ee_u8 retval;
|
||||
retval = ((c >= '0') & (c <= '9')) ? 1 : 0;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Function: core_state_transition
|
||||
Actual state machine.
|
||||
|
||||
The state machine will continue scanning until either:
|
||||
1 - an invalid input is detcted.
|
||||
2 - a valid number has been detected.
|
||||
|
||||
The input pointer is updated to point to the end of the token, and the
|
||||
end state is returned (either specific format determined or invalid).
|
||||
*/
|
||||
|
||||
enum CORE_STATE
|
||||
core_state_transition(ee_u8 **instr, ee_u32 *transition_count)
|
||||
{
|
||||
ee_u8 * str = *instr;
|
||||
ee_u8 NEXT_SYMBOL;
|
||||
enum CORE_STATE state = CORE_START;
|
||||
for (; *str && state != CORE_INVALID; str++)
|
||||
{
|
||||
NEXT_SYMBOL = *str;
|
||||
if (NEXT_SYMBOL == ',') /* end of this input */
|
||||
{
|
||||
str++;
|
||||
break;
|
||||
}
|
||||
switch (state)
|
||||
{
|
||||
case CORE_START:
|
||||
if (ee_isdigit(NEXT_SYMBOL))
|
||||
{
|
||||
state = CORE_INT;
|
||||
}
|
||||
else if (NEXT_SYMBOL == '+' || NEXT_SYMBOL == '-')
|
||||
{
|
||||
state = CORE_S1;
|
||||
}
|
||||
else if (NEXT_SYMBOL == '.')
|
||||
{
|
||||
state = CORE_FLOAT;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = CORE_INVALID;
|
||||
transition_count[CORE_INVALID]++;
|
||||
}
|
||||
transition_count[CORE_START]++;
|
||||
break;
|
||||
case CORE_S1:
|
||||
if (ee_isdigit(NEXT_SYMBOL))
|
||||
{
|
||||
state = CORE_INT;
|
||||
transition_count[CORE_S1]++;
|
||||
}
|
||||
else if (NEXT_SYMBOL == '.')
|
||||
{
|
||||
state = CORE_FLOAT;
|
||||
transition_count[CORE_S1]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = CORE_INVALID;
|
||||
transition_count[CORE_S1]++;
|
||||
}
|
||||
break;
|
||||
case CORE_INT:
|
||||
if (NEXT_SYMBOL == '.')
|
||||
{
|
||||
state = CORE_FLOAT;
|
||||
transition_count[CORE_INT]++;
|
||||
}
|
||||
else if (!ee_isdigit(NEXT_SYMBOL))
|
||||
{
|
||||
state = CORE_INVALID;
|
||||
transition_count[CORE_INT]++;
|
||||
}
|
||||
break;
|
||||
case CORE_FLOAT:
|
||||
if (NEXT_SYMBOL == 'E' || NEXT_SYMBOL == 'e')
|
||||
{
|
||||
state = CORE_S2;
|
||||
transition_count[CORE_FLOAT]++;
|
||||
}
|
||||
else if (!ee_isdigit(NEXT_SYMBOL))
|
||||
{
|
||||
state = CORE_INVALID;
|
||||
transition_count[CORE_FLOAT]++;
|
||||
}
|
||||
break;
|
||||
case CORE_S2:
|
||||
if (NEXT_SYMBOL == '+' || NEXT_SYMBOL == '-')
|
||||
{
|
||||
state = CORE_EXPONENT;
|
||||
transition_count[CORE_S2]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = CORE_INVALID;
|
||||
transition_count[CORE_S2]++;
|
||||
}
|
||||
break;
|
||||
case CORE_EXPONENT:
|
||||
if (ee_isdigit(NEXT_SYMBOL))
|
||||
{
|
||||
state = CORE_SCIENTIFIC;
|
||||
transition_count[CORE_EXPONENT]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = CORE_INVALID;
|
||||
transition_count[CORE_EXPONENT]++;
|
||||
}
|
||||
break;
|
||||
case CORE_SCIENTIFIC:
|
||||
if (!ee_isdigit(NEXT_SYMBOL))
|
||||
{
|
||||
state = CORE_INVALID;
|
||||
transition_count[CORE_INVALID]++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
*instr = str;
|
||||
return state;
|
||||
}
|
||||
249
sdk/software/examples/coremark/core_util.c
Normal file
249
sdk/software/examples/coremark/core_util.c
Normal file
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Original Author: Shay Gal-on
|
||||
*/
|
||||
|
||||
#include "coremark.h"
|
||||
/* Function: get_seed
|
||||
Get a values that cannot be determined at compile time.
|
||||
|
||||
Since different embedded systems and compilers are used, 3 different
|
||||
methods are provided: 1 - Using a volatile variable. This method is only
|
||||
valid if the compiler is forced to generate code that reads the value of a
|
||||
volatile variable from memory at run time. Please note, if using this method,
|
||||
you would need to modify core_portme.c to generate training profile. 2 -
|
||||
Command line arguments. This is the preferred method if command line
|
||||
arguments are supported. 3 - System function. If none of the first 2 methods
|
||||
is available on the platform, a system function which is not a stub can be
|
||||
used.
|
||||
|
||||
e.g. read the value on GPIO pins connected to switches, or invoke
|
||||
special simulator functions.
|
||||
*/
|
||||
#if (SEED_METHOD == SEED_VOLATILE)
|
||||
extern volatile ee_s32 seed1_volatile;
|
||||
extern volatile ee_s32 seed2_volatile;
|
||||
extern volatile ee_s32 seed3_volatile;
|
||||
extern volatile ee_s32 seed4_volatile;
|
||||
extern volatile ee_s32 seed5_volatile;
|
||||
ee_s32
|
||||
get_seed_32(int i)
|
||||
{
|
||||
ee_s32 retval;
|
||||
switch (i)
|
||||
{
|
||||
case 1:
|
||||
retval = seed1_volatile;
|
||||
break;
|
||||
case 2:
|
||||
retval = seed2_volatile;
|
||||
break;
|
||||
case 3:
|
||||
retval = seed3_volatile;
|
||||
break;
|
||||
case 4:
|
||||
retval = seed4_volatile;
|
||||
break;
|
||||
case 5:
|
||||
retval = seed5_volatile;
|
||||
break;
|
||||
default:
|
||||
retval = 0;
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
#elif (SEED_METHOD == SEED_ARG)
|
||||
ee_s32
|
||||
parseval(char *valstring)
|
||||
{
|
||||
ee_s32 retval = 0;
|
||||
ee_s32 neg = 1;
|
||||
int hexmode = 0;
|
||||
if (*valstring == '-')
|
||||
{
|
||||
neg = -1;
|
||||
valstring++;
|
||||
}
|
||||
if ((valstring[0] == '0') && (valstring[1] == 'x'))
|
||||
{
|
||||
hexmode = 1;
|
||||
valstring += 2;
|
||||
}
|
||||
/* first look for digits */
|
||||
if (hexmode)
|
||||
{
|
||||
while (((*valstring >= '0') && (*valstring <= '9'))
|
||||
|| ((*valstring >= 'a') && (*valstring <= 'f')))
|
||||
{
|
||||
ee_s32 digit = *valstring - '0';
|
||||
if (digit > 9)
|
||||
digit = 10 + *valstring - 'a';
|
||||
retval *= 16;
|
||||
retval += digit;
|
||||
valstring++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((*valstring >= '0') && (*valstring <= '9'))
|
||||
{
|
||||
ee_s32 digit = *valstring - '0';
|
||||
retval *= 10;
|
||||
retval += digit;
|
||||
valstring++;
|
||||
}
|
||||
}
|
||||
/* now add qualifiers */
|
||||
if (*valstring == 'K')
|
||||
retval *= 1024;
|
||||
if (*valstring == 'M')
|
||||
retval *= 1024 * 1024;
|
||||
|
||||
retval *= neg;
|
||||
return retval;
|
||||
}
|
||||
|
||||
ee_s32
|
||||
get_seed_args(int i, int argc, char *argv[])
|
||||
{
|
||||
if (argc > i)
|
||||
return parseval(argv[i]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#elif (SEED_METHOD == SEED_FUNC)
|
||||
/* If using OS based function, you must define and implement the functions below
|
||||
* in core_portme.h and core_portme.c ! */
|
||||
ee_s32
|
||||
get_seed_32(int i)
|
||||
{
|
||||
ee_s32 retval;
|
||||
switch (i)
|
||||
{
|
||||
case 1:
|
||||
retval = portme_sys1();
|
||||
break;
|
||||
case 2:
|
||||
retval = portme_sys2();
|
||||
break;
|
||||
case 3:
|
||||
retval = portme_sys3();
|
||||
break;
|
||||
case 4:
|
||||
retval = portme_sys4();
|
||||
break;
|
||||
case 5:
|
||||
retval = portme_sys5();
|
||||
break;
|
||||
default:
|
||||
retval = 0;
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Function: crc*
|
||||
Service functions to calculate 16b CRC code.
|
||||
|
||||
*/
|
||||
ee_u16
|
||||
crcu8(ee_u8 data, ee_u16 crc)
|
||||
{
|
||||
ee_u8 i = 0, x16 = 0, carry = 0;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
x16 = (ee_u8)((data & 1) ^ ((ee_u8)crc & 1));
|
||||
data >>= 1;
|
||||
|
||||
if (x16 == 1)
|
||||
{
|
||||
crc ^= 0x4002;
|
||||
carry = 1;
|
||||
}
|
||||
else
|
||||
carry = 0;
|
||||
crc >>= 1;
|
||||
if (carry)
|
||||
crc |= 0x8000;
|
||||
else
|
||||
crc &= 0x7fff;
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
ee_u16
|
||||
crcu16(ee_u16 newval, ee_u16 crc)
|
||||
{
|
||||
crc = crcu8((ee_u8)(newval), crc);
|
||||
crc = crcu8((ee_u8)((newval) >> 8), crc);
|
||||
return crc;
|
||||
}
|
||||
ee_u16
|
||||
crcu32(ee_u32 newval, ee_u16 crc)
|
||||
{
|
||||
crc = crc16((ee_s16)newval, crc);
|
||||
crc = crc16((ee_s16)(newval >> 16), crc);
|
||||
return crc;
|
||||
}
|
||||
ee_u16
|
||||
crc16(ee_s16 newval, ee_u16 crc)
|
||||
{
|
||||
return crcu16((ee_u16)newval, crc);
|
||||
}
|
||||
|
||||
ee_u8
|
||||
check_data_types()
|
||||
{
|
||||
ee_u8 retval = 0;
|
||||
if (sizeof(ee_u8) != 1)
|
||||
{
|
||||
ee_printf("ERROR: ee_u8 is not an 8b datatype!\n");
|
||||
retval++;
|
||||
}
|
||||
if (sizeof(ee_u16) != 2)
|
||||
{
|
||||
ee_printf("ERROR: ee_u16 is not a 16b datatype!\n");
|
||||
retval++;
|
||||
}
|
||||
if (sizeof(ee_s16) != 2)
|
||||
{
|
||||
ee_printf("ERROR: ee_s16 is not a 16b datatype!\n");
|
||||
retval++;
|
||||
}
|
||||
if (sizeof(ee_s32) != 4)
|
||||
{
|
||||
ee_printf("ERROR: ee_s32 is not a 32b datatype!\n");
|
||||
retval++;
|
||||
}
|
||||
if (sizeof(ee_u32) != 4)
|
||||
{
|
||||
ee_printf("ERROR: ee_u32 is not a 32b datatype!\n");
|
||||
retval++;
|
||||
}
|
||||
if (sizeof(ee_ptr_int) != sizeof(int *))
|
||||
{
|
||||
ee_printf(
|
||||
"ERROR: ee_ptr_int is not a datatype that holds an int pointer!\n");
|
||||
retval++;
|
||||
}
|
||||
if (retval > 0)
|
||||
{
|
||||
ee_printf("ERROR: Please modify the datatypes in core_portme.h!\n");
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
173
sdk/software/examples/coremark/coremark.h
Normal file
173
sdk/software/examples/coremark/coremark.h
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
Author : Shay Gal-On, EEMBC
|
||||
|
||||
This file is part of EEMBC(R) and CoreMark(TM), which are Copyright (C) 2009
|
||||
All rights reserved.
|
||||
|
||||
EEMBC CoreMark Software is a product of EEMBC and is provided under the terms of the
|
||||
CoreMark License that is distributed with the official EEMBC COREMARK Software release.
|
||||
If you received this EEMBC CoreMark Software without the accompanying CoreMark License,
|
||||
you must discontinue use and download the official release from www.coremark.org.
|
||||
|
||||
Also, if you are publicly displaying scores generated from the EEMBC CoreMark software,
|
||||
make sure that you are in compliance with Run and Reporting rules specified in the accompanying readme.txt file.
|
||||
|
||||
EEMBC
|
||||
4354 Town Center Blvd. Suite 114-200
|
||||
El Dorado Hills, CA, 95762
|
||||
*/
|
||||
/* Topic: Description
|
||||
This file contains declarations of the various benchmark functions.
|
||||
*/
|
||||
|
||||
/* Configuration: TOTAL_DATA_SIZE
|
||||
Define total size for data algorithms will operate on
|
||||
*/
|
||||
#ifndef TOTAL_DATA_SIZE
|
||||
#define TOTAL_DATA_SIZE 2*1000
|
||||
#endif
|
||||
|
||||
#define SEED_ARG 0
|
||||
#define SEED_FUNC 1
|
||||
#define SEED_VOLATILE 2
|
||||
|
||||
#define MEM_STATIC 0
|
||||
#define MEM_MALLOC 1
|
||||
#define MEM_STACK 2
|
||||
|
||||
//void uart_initial();
|
||||
#include "core_portme.h"
|
||||
|
||||
#if HAS_STDIO
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#define ee_printf printf
|
||||
/* Actual benchmark execution in iterate */
|
||||
void *iterate(void *pres);
|
||||
|
||||
/* Typedef: secs_ret
|
||||
For machines that have floating point support, get number of seconds as a double.
|
||||
Otherwise an unsigned int.
|
||||
*/
|
||||
#if HAS_FLOAT
|
||||
typedef double secs_ret;
|
||||
#else
|
||||
typedef ee_u32 secs_ret;
|
||||
#endif
|
||||
|
||||
#if MAIN_HAS_NORETURN
|
||||
#define MAIN_RETURN_VAL
|
||||
#define MAIN_RETURN_TYPE void
|
||||
#else
|
||||
#define MAIN_RETURN_VAL 0
|
||||
#define MAIN_RETURN_TYPE int
|
||||
#endif
|
||||
|
||||
void start_time(void);
|
||||
void stop_time(void);
|
||||
CORE_TICKS get_time(void);
|
||||
secs_ret time_in_secs(CORE_TICKS ticks);
|
||||
|
||||
/* Misc useful functions */
|
||||
ee_u16 crcu8(ee_u8 data, ee_u16 crc);
|
||||
ee_u16 crc16(ee_s16 newval, ee_u16 crc);
|
||||
ee_u16 crcu16(ee_u16 newval, ee_u16 crc);
|
||||
ee_u16 crcu32(ee_u32 newval, ee_u16 crc);
|
||||
ee_u8 check_data_types();
|
||||
void *portable_malloc(ee_size_t size);
|
||||
void portable_free(void *p);
|
||||
ee_s32 parseval(char *valstring);
|
||||
|
||||
/* Algorithm IDS */
|
||||
#define ID_LIST (1<<0)
|
||||
#define ID_MATRIX (1<<1)
|
||||
#define ID_STATE (1<<2)
|
||||
#define ALL_ALGORITHMS_MASK (ID_LIST|ID_MATRIX|ID_STATE)
|
||||
#define NUM_ALGORITHMS 3
|
||||
|
||||
/* list data structures */
|
||||
typedef struct list_data_s {
|
||||
ee_s16 data16;
|
||||
ee_s16 idx;
|
||||
} list_data;
|
||||
|
||||
typedef struct list_head_s {
|
||||
struct list_head_s *next;
|
||||
struct list_data_s *info;
|
||||
} list_head;
|
||||
|
||||
|
||||
/*matrix benchmark related stuff */
|
||||
#define MATDAT_INT 1
|
||||
#if MATDAT_INT
|
||||
typedef ee_s16 MATDAT;
|
||||
typedef ee_s32 MATRES;
|
||||
#else
|
||||
typedef ee_f16 MATDAT;
|
||||
typedef ee_f32 MATRES;
|
||||
#endif
|
||||
|
||||
typedef struct MAT_PARAMS_S {
|
||||
int N;
|
||||
MATDAT *A;
|
||||
MATDAT *B;
|
||||
MATRES *C;
|
||||
} mat_params;
|
||||
|
||||
/* state machine related stuff */
|
||||
/* List of all the possible states for the FSM */
|
||||
typedef enum CORE_STATE {
|
||||
CORE_START=0,
|
||||
CORE_INVALID,
|
||||
CORE_S1,
|
||||
CORE_S2,
|
||||
CORE_INT,
|
||||
CORE_FLOAT,
|
||||
CORE_EXPONENT,
|
||||
CORE_SCIENTIFIC,
|
||||
NUM_CORE_STATES
|
||||
} core_state_e ;
|
||||
|
||||
|
||||
/* Helper structure to hold results */
|
||||
typedef struct RESULTS_S {
|
||||
/* inputs */
|
||||
ee_s16 seed1; /* Initializing seed */
|
||||
ee_s16 seed2; /* Initializing seed */
|
||||
ee_s16 seed3; /* Initializing seed */
|
||||
void *memblock[4]; /* Pointer to safe memory location */
|
||||
ee_u32 size; /* Size of the data */
|
||||
ee_u32 iterations; /* Number of iterations to execute */
|
||||
ee_u32 execs; /* Bitmask of operations to execute */
|
||||
struct list_head_s *list;
|
||||
mat_params mat;
|
||||
/* outputs */
|
||||
ee_u16 crc;
|
||||
ee_u16 crclist;
|
||||
ee_u16 crcmatrix;
|
||||
ee_u16 crcstate;
|
||||
ee_s16 err;
|
||||
/* ultithread specific */
|
||||
core_portable port;
|
||||
} core_results;
|
||||
|
||||
/* Multicore execution handling */
|
||||
#if (MULTITHREAD>1)
|
||||
ee_u8 core_start_parallel(core_results *res);
|
||||
ee_u8 core_stop_parallel(core_results *res);
|
||||
#endif
|
||||
|
||||
/* list benchmark functions */
|
||||
list_head *core_list_init(ee_u32 blksize, list_head *memblock, ee_s16 seed);
|
||||
ee_u16 core_bench_list(core_results *res, ee_s16 finder_idx);
|
||||
|
||||
/* state benchmark functions */
|
||||
void core_init_state(ee_u32 size, ee_s16 seed, ee_u8 *p);
|
||||
ee_u16 core_bench_state(ee_u32 blksize, ee_u8 *memblock,
|
||||
ee_s16 seed1, ee_s16 seed2, ee_s16 step, ee_u16 crc);
|
||||
|
||||
/* matrix benchmark functions */
|
||||
ee_u32 core_init_matrix(ee_u32 blksize, void *memblk, ee_s32 seed, mat_params *p);
|
||||
ee_u16 core_bench_matrix(mat_params *p, ee_s16 seed, ee_u16 crc);
|
||||
|
||||
16
sdk/software/examples/dhrystone/Makefile
Normal file
16
sdk/software/examples/dhrystone/Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
TARGET = dhrystone
|
||||
|
||||
CFLAGS += -O3 -g -G8 -DTIME -DNumber_Of_Runs=1
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
INCLUDES := -I.
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../bsp
|
||||
GCC_DIR=../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../toolchains/picolibc
|
||||
include ../../bsp/common.mk
|
||||
10
sdk/software/examples/dhrystone/README.md
Normal file
10
sdk/software/examples/dhrystone/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
Multiple versions of Reinhold P. Weicker's **Dhrystone** benchmark
|
||||
|
||||
Sources downloaded and extracted from old Usenet postings and from
|
||||
sites linked from http://en.wikipedia.org/wiki/Dhrystone
|
||||
|
||||
The `original-sources` directory contains the raw sources. Each
|
||||
subdirectory `v1`, `v2.0`, `v2.1`, `v2.2` contains an extracted
|
||||
version; see the `_README` file in each directory.
|
||||
|
||||
version in this dir is v2.1
|
||||
420
sdk/software/examples/dhrystone/dhry.h
Normal file
420
sdk/software/examples/dhrystone/dhry.h
Normal file
@@ -0,0 +1,420 @@
|
||||
/*
|
||||
****************************************************************************
|
||||
*
|
||||
* "DHRYSTONE" Benchmark Program
|
||||
* -----------------------------
|
||||
*
|
||||
* Version: C, Version 2.1
|
||||
*
|
||||
* File: dhry.h (part 1 of 3)
|
||||
*
|
||||
* Date: May 25, 1988
|
||||
*
|
||||
* Author: Reinhold P. Weicker
|
||||
* Siemens AG, AUT E 51
|
||||
* Postfach 3220
|
||||
* 8520 Erlangen
|
||||
* Germany (West)
|
||||
* Phone: [+49]-9131-7-20330
|
||||
* (8-17 Central European Time)
|
||||
* Usenet: ..!mcsun!unido!estevax!weicker
|
||||
*
|
||||
* Original Version (in Ada) published in
|
||||
* "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
|
||||
* pp. 1013 - 1030, together with the statistics
|
||||
* on which the distribution of statements etc. is based.
|
||||
*
|
||||
* In this C version, the following C library functions are used:
|
||||
* - strcpy, strcmp (inside the measurement loop)
|
||||
* - printf, scanf (outside the measurement loop)
|
||||
* In addition, Berkeley UNIX system calls "times ()" or "time ()"
|
||||
* are used for execution time measurement. For measurements
|
||||
* on other systems, these calls have to be changed.
|
||||
*
|
||||
* Collection of Results:
|
||||
* Reinhold Weicker (address see above) and
|
||||
*
|
||||
* Rick Richardson
|
||||
* PC Research. Inc.
|
||||
* 94 Apple Orchard Drive
|
||||
* Tinton Falls, NJ 07724
|
||||
* Phone: (201) 389-8963 (9-17 EST)
|
||||
* Usenet: ...!uunet!pcrat!rick
|
||||
*
|
||||
* Please send results to Rick Richardson and/or Reinhold Weicker.
|
||||
* Complete information should be given on hardware and software used.
|
||||
* Hardware information includes: Machine type, CPU, type and size
|
||||
* of caches; for microprocessors: clock frequency, memory speed
|
||||
* (number of wait states).
|
||||
* Software information includes: Compiler (and runtime library)
|
||||
* manufacturer and version, compilation switches, OS version.
|
||||
* The Operating System version may give an indication about the
|
||||
* compiler; Dhrystone itself performs no OS calls in the measurement loop.
|
||||
*
|
||||
* The complete output generated by the program should be mailed
|
||||
* such that at least some checks for correctness can be made.
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* History: This version C/2.1 has been made for two reasons:
|
||||
*
|
||||
* 1) There is an obvious need for a common C version of
|
||||
* Dhrystone, since C is at present the most popular system
|
||||
* programming language for the class of processors
|
||||
* (microcomputers, minicomputers) where Dhrystone is used most.
|
||||
* There should be, as far as possible, only one C version of
|
||||
* Dhrystone such that results can be compared without
|
||||
* restrictions. In the past, the C versions distributed
|
||||
* by Rick Richardson (Version 1.1) and by Reinhold Weicker
|
||||
* had small (though not significant) differences.
|
||||
*
|
||||
* 2) As far as it is possible without changes to the Dhrystone
|
||||
* statistics, optimizing compilers should be prevented from
|
||||
* removing significant statements.
|
||||
*
|
||||
* This C version has been developed in cooperation with
|
||||
* Rick Richardson (Tinton Falls, NJ), it incorporates many
|
||||
* ideas from the "Version 1.1" distributed previously by
|
||||
* him over the UNIX network Usenet.
|
||||
* I also thank Chaim Benedelac (National Semiconductor),
|
||||
* David Ditzel (SUN), Earl Killian and John Mashey (MIPS),
|
||||
* Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)
|
||||
* for their help with comments on earlier versions of the
|
||||
* benchmark.
|
||||
*
|
||||
* Changes: In the initialization part, this version follows mostly
|
||||
* Rick Richardson's version distributed via Usenet, not the
|
||||
* version distributed earlier via floppy disk by Reinhold Weicker.
|
||||
* As a concession to older compilers, names have been made
|
||||
* unique within the first 8 characters.
|
||||
* Inside the measurement loop, this version follows the
|
||||
* version previously distributed by Reinhold Weicker.
|
||||
*
|
||||
* At several places in the benchmark, code has been added,
|
||||
* but within the measurement loop only in branches that
|
||||
* are not executed. The intention is that optimizing compilers
|
||||
* should be prevented from moving code out of the measurement
|
||||
* loop, or from removing code altogether. Since the statements
|
||||
* that are executed within the measurement loop have NOT been
|
||||
* changed, the numbers defining the "Dhrystone distribution"
|
||||
* (distribution of statements, operand types and locality)
|
||||
* still hold. Except for sophisticated optimizing compilers,
|
||||
* execution times for this version should be the same as
|
||||
* for previous versions.
|
||||
*
|
||||
* Since it has proven difficult to subtract the time for the
|
||||
* measurement loop overhead in a correct way, the loop check
|
||||
* has been made a part of the benchmark. This does have
|
||||
* an impact - though a very minor one - on the distribution
|
||||
* statistics which have been updated for this version.
|
||||
*
|
||||
* All changes within the measurement loop are described
|
||||
* and discussed in the companion paper "Rationale for
|
||||
* Dhrystone version 2".
|
||||
*
|
||||
* Because of the self-imposed limitation that the order and
|
||||
* distribution of the executed statements should not be
|
||||
* changed, there are still cases where optimizing compilers
|
||||
* may not generate code for some statements. To a certain
|
||||
* degree, this is unavoidable for small synthetic benchmarks.
|
||||
* Users of the benchmark are advised to check code listings
|
||||
* whether code is generated for all statements of Dhrystone.
|
||||
*
|
||||
* Version 2.1 is identical to version 2.0 distributed via
|
||||
* the UNIX network Usenet in March 1988 except that it corrects
|
||||
* some minor deficiencies that were found by users of version 2.0.
|
||||
* The only change within the measurement loop is that a
|
||||
* non-executed "else" part was added to the "if" statement in
|
||||
* Func_3, and a non-executed "else" part removed from Proc_3.
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Defines: The following "Defines" are possible:
|
||||
* -DREG=register (default: Not defined)
|
||||
* As an approximation to what an average C programmer
|
||||
* might do, the "register" storage class is applied
|
||||
* (if enabled by -DREG=register)
|
||||
* - for local variables, if they are used (dynamically)
|
||||
* five or more times
|
||||
* - for parameters if they are used (dynamically)
|
||||
* six or more times
|
||||
* Note that an optimal "register" strategy is
|
||||
* compiler-dependent, and that "register" declarations
|
||||
* do not necessarily lead to faster execution.
|
||||
* -DNOSTRUCTASSIGN (default: Not defined)
|
||||
* Define if the C compiler does not support
|
||||
* assignment of structures.
|
||||
* -DNOENUMS (default: Not defined)
|
||||
* Define if the C compiler does not support
|
||||
* enumeration types.
|
||||
* -DTIMES (default)
|
||||
* -DTIME
|
||||
* The "times" function of UNIX (returning process times)
|
||||
* or the "time" function (returning wallclock time)
|
||||
* is used for measurement.
|
||||
* For single user machines, "time ()" is adequate. For
|
||||
* multi-user machines where you cannot get single-user
|
||||
* access, use the "times ()" function. If you have
|
||||
* neither, use a stopwatch in the dead of night.
|
||||
* "printf"s are provided marking the points "Start Timer"
|
||||
* and "Stop Timer". DO NOT use the UNIX "time(1)"
|
||||
* command, as this will measure the total time to
|
||||
* run this program, which will (erroneously) include
|
||||
* the time to allocate storage (malloc) and to perform
|
||||
* the initialization.
|
||||
* -DHZ=nnn
|
||||
* In Berkeley UNIX, the function "times" returns process
|
||||
* time in 1/HZ seconds, with HZ = 60 for most systems.
|
||||
* CHECK YOUR SYSTEM DESCRIPTION BEFORE YOU JUST APPLY
|
||||
* A VALUE.
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Compilation model and measurement (IMPORTANT):
|
||||
*
|
||||
* This C version of Dhrystone consists of three files:
|
||||
* - dhry.h (this file, containing global definitions and comments)
|
||||
* - dhry_1.c (containing the code corresponding to Ada package Pack_1)
|
||||
* - dhry_2.c (containing the code corresponding to Ada package Pack_2)
|
||||
*
|
||||
* The following "ground rules" apply for measurements:
|
||||
* - Separate compilation
|
||||
* - No procedure merging
|
||||
* - Otherwise, compiler optimizations are allowed but should be indicated
|
||||
* - Default results are those without register declarations
|
||||
* See the companion paper "Rationale for Dhrystone Version 2" for a more
|
||||
* detailed discussion of these ground rules.
|
||||
*
|
||||
* For 16-Bit processors (e.g. 80186, 80286), times for all compilation
|
||||
* models ("small", "medium", "large" etc.) should be given if possible,
|
||||
* together with a definition of these models for the compiler system used.
|
||||
*
|
||||
**************************************************************************
|
||||
*
|
||||
* Dhrystone (C version) statistics:
|
||||
*
|
||||
* [Comment from the first distribution, updated for version 2.
|
||||
* Note that because of language differences, the numbers are slightly
|
||||
* different from the Ada version.]
|
||||
*
|
||||
* The following program contains statements of a high level programming
|
||||
* language (here: C) in a distribution considered representative:
|
||||
*
|
||||
* assignments 52 (51.0 %)
|
||||
* control statements 33 (32.4 %)
|
||||
* procedure, function calls 17 (16.7 %)
|
||||
*
|
||||
* 103 statements are dynamically executed. The program is balanced with
|
||||
* respect to the three aspects:
|
||||
*
|
||||
* - statement type
|
||||
* - operand type
|
||||
* - operand locality
|
||||
* operand global, local, parameter, or constant.
|
||||
*
|
||||
* The combination of these three aspects is balanced only approximately.
|
||||
*
|
||||
* 1. Statement Type:
|
||||
* ----------------- number
|
||||
*
|
||||
* V1 = V2 9
|
||||
* (incl. V1 = F(..)
|
||||
* V = Constant 12
|
||||
* Assignment, 7
|
||||
* with array element
|
||||
* Assignment, 6
|
||||
* with record component
|
||||
* --
|
||||
* 34 34
|
||||
*
|
||||
* X = Y +|-|"&&"|"|" Z 5
|
||||
* X = Y +|-|"==" Constant 6
|
||||
* X = X +|- 1 3
|
||||
* X = Y *|/ Z 2
|
||||
* X = Expression, 1
|
||||
* two operators
|
||||
* X = Expression, 1
|
||||
* three operators
|
||||
* --
|
||||
* 18 18
|
||||
*
|
||||
* if .... 14
|
||||
* with "else" 7
|
||||
* without "else" 7
|
||||
* executed 3
|
||||
* not executed 4
|
||||
* for ... 7 | counted every time
|
||||
* while ... 4 | the loop condition
|
||||
* do ... while 1 | is evaluated
|
||||
* switch ... 1
|
||||
* break 1
|
||||
* declaration with 1
|
||||
* initialization
|
||||
* --
|
||||
* 34 34
|
||||
*
|
||||
* P (...) procedure call 11
|
||||
* user procedure 10
|
||||
* library procedure 1
|
||||
* X = F (...)
|
||||
* function call 6
|
||||
* user function 5
|
||||
* library function 1
|
||||
* --
|
||||
* 17 17
|
||||
* ---
|
||||
* 103
|
||||
*
|
||||
* The average number of parameters in procedure or function calls
|
||||
* is 1.82 (not counting the function values as implicit parameters).
|
||||
*
|
||||
*
|
||||
* 2. Operators
|
||||
* ------------
|
||||
* number approximate
|
||||
* percentage
|
||||
*
|
||||
* Arithmetic 32 50.8
|
||||
*
|
||||
* + 21 33.3
|
||||
* - 7 11.1
|
||||
* * 3 4.8
|
||||
* / (int div) 1 1.6
|
||||
*
|
||||
* Comparison 27 42.8
|
||||
*
|
||||
* == 9 14.3
|
||||
* /= 4 6.3
|
||||
* > 1 1.6
|
||||
* < 3 4.8
|
||||
* >= 1 1.6
|
||||
* <= 9 14.3
|
||||
*
|
||||
* Logic 4 6.3
|
||||
*
|
||||
* && (AND-THEN) 1 1.6
|
||||
* | (OR) 1 1.6
|
||||
* ! (NOT) 2 3.2
|
||||
*
|
||||
* -- -----
|
||||
* 63 100.1
|
||||
*
|
||||
*
|
||||
* 3. Operand Type (counted once per operand reference):
|
||||
* ---------------
|
||||
* number approximate
|
||||
* percentage
|
||||
*
|
||||
* Integer 175 72.3 %
|
||||
* Character 45 18.6 %
|
||||
* Pointer 12 5.0 %
|
||||
* String30 6 2.5 %
|
||||
* Array 2 0.8 %
|
||||
* Record 2 0.8 %
|
||||
* --- -------
|
||||
* 242 100.0 %
|
||||
*
|
||||
* When there is an access path leading to the final operand (e.g. a record
|
||||
* component), only the final data type on the access path is counted.
|
||||
*
|
||||
*
|
||||
* 4. Operand Locality:
|
||||
* -------------------
|
||||
* number approximate
|
||||
* percentage
|
||||
*
|
||||
* local variable 114 47.1 %
|
||||
* global variable 22 9.1 %
|
||||
* parameter 45 18.6 %
|
||||
* value 23 9.5 %
|
||||
* reference 22 9.1 %
|
||||
* function result 6 2.5 %
|
||||
* constant 55 22.7 %
|
||||
* --- -------
|
||||
* 242 100.0 %
|
||||
*
|
||||
*
|
||||
* The program does not compute anything meaningful, but it is syntactically
|
||||
* and semantically correct. All variables have a value assigned to them
|
||||
* before they are used as a source operand.
|
||||
*
|
||||
* There has been no explicit effort to account for the effects of a
|
||||
* cache, or to balance the use of long or short displacements for code or
|
||||
* data.
|
||||
*
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
/* Compiler and system dependent definitions: */
|
||||
|
||||
#ifndef TIME
|
||||
#define TIMES
|
||||
#endif
|
||||
/* Use times(2) time function unless */
|
||||
/* explicitly defined otherwise */
|
||||
|
||||
|
||||
#define Mic_secs_Per_Second 1000000
|
||||
/* Berkeley UNIX C returns process times in seconds/HZ */
|
||||
|
||||
#ifdef NOSTRUCTASSIGN
|
||||
#define structassign(d, s) memcpy(&(d), &(s), sizeof(d))
|
||||
#else
|
||||
#define structassign(d, s) d = s
|
||||
#endif
|
||||
|
||||
#ifdef NOENUM
|
||||
#define Ident_1 0
|
||||
#define Ident_2 1
|
||||
#define Ident_3 2
|
||||
#define Ident_4 3
|
||||
#define Ident_5 4
|
||||
typedef int Enumeration;
|
||||
#else
|
||||
typedef enum {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
|
||||
Enumeration;
|
||||
#endif
|
||||
/* for boolean and enumeration types in Ada, Pascal */
|
||||
|
||||
/* General definitions: */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "confreg_time.h"
|
||||
/* for strcpy, strcmp */
|
||||
|
||||
#define Null 0
|
||||
/* Value of a Null pointer */
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
typedef int One_Thirty;
|
||||
typedef int One_Fifty;
|
||||
typedef char Capital_Letter;
|
||||
typedef int Boolean;
|
||||
typedef char Str_30 [31];
|
||||
typedef int Arr_1_Dim [50];
|
||||
typedef int Arr_2_Dim [50] [50];
|
||||
|
||||
typedef struct record
|
||||
{
|
||||
struct record *Ptr_Comp;
|
||||
Enumeration Discr;
|
||||
union {
|
||||
struct {
|
||||
Enumeration Enum_Comp;
|
||||
int Int_Comp;
|
||||
char Str_Comp [31];
|
||||
} var_1;
|
||||
struct {
|
||||
Enumeration E_Comp_2;
|
||||
char Str_2_Comp [31];
|
||||
} var_2;
|
||||
struct {
|
||||
char Ch_1_Comp;
|
||||
char Ch_2_Comp;
|
||||
} var_3;
|
||||
} variant;
|
||||
} Rec_Type, *Rec_Pointer;
|
||||
|
||||
|
||||
392
sdk/software/examples/dhrystone/dhry_1.c
Normal file
392
sdk/software/examples/dhrystone/dhry_1.c
Normal file
@@ -0,0 +1,392 @@
|
||||
/*
|
||||
****************************************************************************
|
||||
*
|
||||
* "DHRYSTONE" Benchmark Program
|
||||
* -----------------------------
|
||||
*
|
||||
* Version: C, Version 2.1
|
||||
*
|
||||
* File: dhry_1.c (part 2 of 3)
|
||||
*
|
||||
* Date: May 25, 1988
|
||||
*
|
||||
* Author: Reinhold P. Weicker
|
||||
*
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "dhry.h"
|
||||
|
||||
/* Global Variables: */
|
||||
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbfe001e0; //UART16550的虚地址
|
||||
unsigned long CONFREG_UART_BASE = 0xbfafff10; //CONFREG模拟UART的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbfafe000; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 100000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
Rec_Pointer Ptr_Glob,
|
||||
Next_Ptr_Glob;
|
||||
int Int_Glob;
|
||||
Boolean Bool_Glob;
|
||||
char Ch_1_Glob,
|
||||
Ch_2_Glob;
|
||||
int Arr_1_Glob [50];
|
||||
int Arr_2_Glob [50] [50];
|
||||
|
||||
Enumeration Func_1 ();
|
||||
|
||||
/* forward declaration necessary since Enumeration may not simply be int */
|
||||
|
||||
#ifndef REG
|
||||
Boolean Reg = false;
|
||||
#define REG
|
||||
/* REG becomes defined as empty */
|
||||
/* i.e. no register variables */
|
||||
#else
|
||||
Boolean Reg = true;
|
||||
#endif
|
||||
|
||||
/* variables for time measurement: */
|
||||
|
||||
/* see library function "times" */
|
||||
#define Too_Small_Time 120
|
||||
/* Measurements should last at least about 2 seconds */
|
||||
|
||||
long Begin_Time,
|
||||
End_Time,
|
||||
User_Time;
|
||||
|
||||
float Microseconds,
|
||||
Dhrystones_Per_Second;
|
||||
|
||||
Rec_Type Next_Rec_Glob;
|
||||
Rec_Type Rec_Glob;
|
||||
/* end of variables for time measurement */
|
||||
|
||||
void* malloc(size_t);
|
||||
|
||||
int main (int argc, char** argv)
|
||||
/*****/
|
||||
|
||||
/* main program, corresponds to procedures */
|
||||
/* Main and Proc_0 in the Ada version */
|
||||
{
|
||||
One_Fifty Int_1_Loc;
|
||||
REG One_Fifty Int_2_Loc;
|
||||
One_Fifty Int_3_Loc;
|
||||
REG char Ch_Index;
|
||||
Enumeration Enum_Loc;
|
||||
Str_30 Str_1_Loc;
|
||||
Str_30 Str_2_Loc;
|
||||
REG int Run_Index;
|
||||
|
||||
/* Initializations */
|
||||
printf ("\n");
|
||||
printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
|
||||
printf ("\n");
|
||||
|
||||
// Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
|
||||
// Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
|
||||
Next_Ptr_Glob = (Rec_Pointer)&Next_Rec_Glob;
|
||||
Ptr_Glob = (Rec_Pointer)&Rec_Glob;
|
||||
|
||||
Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
|
||||
Ptr_Glob->Discr = Ident_1;
|
||||
Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
|
||||
Ptr_Glob->variant.var_1.Int_Comp = 40;
|
||||
strcpy (Ptr_Glob->variant.var_1.Str_Comp,
|
||||
"DHRYSTONE PROGRAM, SOME STRING");
|
||||
strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
|
||||
|
||||
Arr_2_Glob [8][7] = 10;
|
||||
/* Was missing in published program. Without this statement, */
|
||||
/* Arr_2_Glob [8][7] would have an undefined value. */
|
||||
/* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
|
||||
/* overflow may occur for this array element. */
|
||||
|
||||
printf("\n");
|
||||
printf("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
|
||||
printf("\n");
|
||||
if (Reg)
|
||||
{
|
||||
printf ("Program compiled with 'register' attribute\n");
|
||||
printf ("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("Program compiled without 'register' attribute\n");
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
|
||||
|
||||
/***************/
|
||||
/* Start timer */
|
||||
/***************/
|
||||
|
||||
Begin_Time = get_ns();
|
||||
|
||||
for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
|
||||
{
|
||||
|
||||
Proc_5();
|
||||
Proc_4();
|
||||
/* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
|
||||
Int_1_Loc = 2;
|
||||
Int_2_Loc = 3;
|
||||
strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
|
||||
Enum_Loc = Ident_2;
|
||||
Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
|
||||
/* Bool_Glob == 1 */
|
||||
while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
|
||||
{
|
||||
Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
|
||||
/* Int_3_Loc == 7 */
|
||||
Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
|
||||
/* Int_3_Loc == 7 */
|
||||
Int_1_Loc += 1;
|
||||
} /* while */
|
||||
/* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
|
||||
Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
|
||||
/* Int_Glob == 5 */
|
||||
Proc_1 (Ptr_Glob);
|
||||
for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
|
||||
/* loop body executed twice */
|
||||
{
|
||||
if (Enum_Loc == Func_1 (Ch_Index, 'C'))
|
||||
/* then, not executed */
|
||||
{
|
||||
Proc_6 (Ident_1, &Enum_Loc);
|
||||
strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
|
||||
Int_2_Loc = Run_Index;
|
||||
Int_Glob = Run_Index;
|
||||
}
|
||||
}
|
||||
/* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
|
||||
Int_2_Loc = Int_2_Loc * Int_1_Loc;
|
||||
Int_1_Loc = Int_2_Loc / Int_3_Loc;
|
||||
Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
|
||||
/* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
|
||||
Proc_2 (&Int_1_Loc);
|
||||
/* Int_1_Loc == 5 */
|
||||
|
||||
} /* loop "for Run_Index" */
|
||||
|
||||
/**************/
|
||||
/* Stop timer */
|
||||
/**************/
|
||||
|
||||
End_Time = get_ns();
|
||||
|
||||
printf ("Execution ends\n");
|
||||
printf ("\n");
|
||||
printf ("Final values of the variables used in the benchmark:\n");
|
||||
printf ("\n");
|
||||
printf ("Int_Glob: %d\n", Int_Glob);
|
||||
printf (" should be: %d\n", 5);
|
||||
printf ("Bool_Glob: %d\n", Bool_Glob);
|
||||
printf (" should be: %d\n", 1);
|
||||
printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
|
||||
printf (" should be: %c\n", 'A');
|
||||
printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
|
||||
printf (" should be: %c\n", 'B');
|
||||
printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
|
||||
printf (" should be: %d\n", 7);
|
||||
printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
|
||||
printf (" should be: %d\n", Number_Of_Runs + 10);
|
||||
printf ("Ptr_Glob->\n");
|
||||
printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
|
||||
printf (" should be: (implementation-dependent)\n");
|
||||
printf (" Discr: %d\n", Ptr_Glob->Discr);
|
||||
printf (" should be: %d\n", 0);
|
||||
printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
|
||||
printf (" should be: %d\n", 2);
|
||||
printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
|
||||
printf (" should be: %d\n", 17);
|
||||
printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
|
||||
printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
|
||||
printf ("Next_Ptr_Glob->\n");
|
||||
printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
|
||||
printf (" should be: (implementation-dependent), same as above\n");
|
||||
printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
|
||||
printf (" should be: %d\n", 0);
|
||||
printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
|
||||
printf (" should be: %d\n", 1);
|
||||
printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
|
||||
printf (" should be: %d\n", 18);
|
||||
printf (" Str_Comp: %s\n",
|
||||
Next_Ptr_Glob->variant.var_1.Str_Comp);
|
||||
printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
|
||||
printf ("Int_1_Loc: %d\n", Int_1_Loc);
|
||||
printf (" should be: %d\n", 5);
|
||||
printf ("Int_2_Loc: %d\n", Int_2_Loc);
|
||||
printf (" should be: %d\n", 13);
|
||||
printf ("Int_3_Loc: %d\n", Int_3_Loc);
|
||||
printf (" should be: %d\n", 7);
|
||||
printf ("Enum_Loc: %d\n", Enum_Loc);
|
||||
printf (" should be: %d\n", 1);
|
||||
printf ("Str_1_Loc: %s\n", Str_1_Loc);
|
||||
printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
|
||||
printf ("Str_2_Loc: %s\n", Str_2_Loc);
|
||||
printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
|
||||
printf ("\n");
|
||||
|
||||
int pass = 0;
|
||||
if (Int_Glob == 5) ; else pass = 1;
|
||||
if (Bool_Glob == 1) ; else pass = 1;
|
||||
if (Ch_1_Glob == 'A') ; else pass = 1;
|
||||
if (Ch_2_Glob == 'B') ; else pass = 1;
|
||||
if (Arr_1_Glob[8] == 7) ; else pass = 1;
|
||||
if ((Arr_2_Glob[8][7] == Number_Of_Runs + 10)) ; else pass = 1;
|
||||
if ((int) Ptr_Glob->Ptr_Comp == (int) Next_Ptr_Glob->Ptr_Comp) ; else pass = 1;
|
||||
if (Ptr_Glob->Discr == 0) ; else pass = 1;
|
||||
if (Ptr_Glob->variant.var_1.Enum_Comp == 2) ; else pass = 1;
|
||||
if (Ptr_Glob->variant.var_1.Int_Comp == 17) ; else pass = 1;
|
||||
if (strcmp(Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING") == 0) ; else pass = 1;
|
||||
if (Next_Ptr_Glob->Discr == 0) ; else pass = 1;
|
||||
if (Next_Ptr_Glob->variant.var_1.Enum_Comp == 1) ; else pass = 1;
|
||||
if (Next_Ptr_Glob->variant.var_1.Int_Comp == 18) ; else pass = 1;
|
||||
if (strcmp(Next_Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING") == 0) ; else pass = 1;
|
||||
if (Int_1_Loc == 5) ; else pass = 1;
|
||||
if (Int_2_Loc == 13) ; else pass = 1;
|
||||
if (Int_3_Loc == 7) ; else pass = 1;
|
||||
if (Enum_Loc == 1) ; else pass = 1;
|
||||
if (strcmp(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING") == 0) ; else pass = 1;
|
||||
if (strcmp(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING") == 0) ; else pass = 1;
|
||||
|
||||
User_Time = End_Time - Begin_Time;
|
||||
printf ("Begin ns: %lu\n",Begin_Time);
|
||||
printf ("End ns: %lu\n",End_Time);
|
||||
printf ("Total ns: %lu\n",User_Time);
|
||||
|
||||
|
||||
if (User_Time < Too_Small_Time)
|
||||
{
|
||||
printf ("Measured time too small to obtain meaningful results\n");
|
||||
printf ("Please increase number of runs\n");
|
||||
printf ("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Microseconds = (float) User_Time /(float) Number_Of_Runs/(float)1000000;
|
||||
Dhrystones_Per_Second = ((float) 1000000000 * (float) Number_Of_Runs)
|
||||
/ (float) User_Time;
|
||||
|
||||
printf ("Microseconds for one run through Dhrystone: ");
|
||||
printf ("%10.1f \n", Microseconds);
|
||||
printf ("Dhrystones per Second: ");
|
||||
printf ("%10.0f \n", Dhrystones_Per_Second);
|
||||
printf ("\n");
|
||||
}
|
||||
return pass;
|
||||
}
|
||||
|
||||
|
||||
Proc_1 (Ptr_Val_Par)
|
||||
/******************/
|
||||
|
||||
REG Rec_Pointer Ptr_Val_Par;
|
||||
/* executed once */
|
||||
{
|
||||
REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
|
||||
/* == Ptr_Glob_Next */
|
||||
/* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
|
||||
/* corresponds to "rename" in Ada, "with" in Pascal */
|
||||
|
||||
structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
|
||||
Ptr_Val_Par->variant.var_1.Int_Comp = 5;
|
||||
Next_Record->variant.var_1.Int_Comp
|
||||
= Ptr_Val_Par->variant.var_1.Int_Comp;
|
||||
Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
|
||||
Proc_3 (&Next_Record->Ptr_Comp);
|
||||
/* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
|
||||
== Ptr_Glob->Ptr_Comp */
|
||||
if (Next_Record->Discr == Ident_1)
|
||||
/* then, executed */
|
||||
{
|
||||
Next_Record->variant.var_1.Int_Comp = 6;
|
||||
Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
|
||||
&Next_Record->variant.var_1.Enum_Comp);
|
||||
Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
|
||||
Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
|
||||
&Next_Record->variant.var_1.Int_Comp);
|
||||
}
|
||||
else /* not executed */
|
||||
structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
|
||||
} /* Proc_1 */
|
||||
|
||||
|
||||
Proc_2 (Int_Par_Ref)
|
||||
/******************/
|
||||
/* executed once */
|
||||
/* *Int_Par_Ref == 1, becomes 4 */
|
||||
|
||||
One_Fifty *Int_Par_Ref;
|
||||
{
|
||||
One_Fifty Int_Loc;
|
||||
Enumeration Enum_Loc;
|
||||
|
||||
Int_Loc = *Int_Par_Ref + 10;
|
||||
do /* executed once */
|
||||
if (Ch_1_Glob == 'A')
|
||||
/* then, executed */
|
||||
{
|
||||
Int_Loc -= 1;
|
||||
*Int_Par_Ref = Int_Loc - Int_Glob;
|
||||
Enum_Loc = Ident_1;
|
||||
} /* if */
|
||||
while (Enum_Loc != Ident_1); /* true */
|
||||
} /* Proc_2 */
|
||||
|
||||
|
||||
Proc_3 (Ptr_Ref_Par)
|
||||
/******************/
|
||||
/* executed once */
|
||||
/* Ptr_Ref_Par becomes Ptr_Glob */
|
||||
|
||||
Rec_Pointer *Ptr_Ref_Par;
|
||||
|
||||
{
|
||||
if (Ptr_Glob != Null)
|
||||
/* then, executed */
|
||||
*Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
|
||||
Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
|
||||
} /* Proc_3 */
|
||||
|
||||
|
||||
Proc_4 () /* without parameters */
|
||||
/*******/
|
||||
/* executed once */
|
||||
{
|
||||
Boolean Bool_Loc;
|
||||
|
||||
Bool_Loc = Ch_1_Glob == 'A';
|
||||
Bool_Glob = Bool_Loc | Bool_Glob;
|
||||
Ch_2_Glob = 'B';
|
||||
} /* Proc_4 */
|
||||
|
||||
|
||||
Proc_5 () /* without parameters */
|
||||
/*******/
|
||||
/* executed once */
|
||||
{
|
||||
Ch_1_Glob = 'A';
|
||||
Bool_Glob = false;
|
||||
} /* Proc_5 */
|
||||
|
||||
|
||||
/* Procedure for the assignment of structures, */
|
||||
/* if the C compiler doesn't support this feature */
|
||||
#ifdef NOSTRUCTASSIGN
|
||||
memcpy (d, s, l)
|
||||
register char *d;
|
||||
register char *s;
|
||||
register int l;
|
||||
{
|
||||
while (l--) *d++ = *s++;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
192
sdk/software/examples/dhrystone/dhry_2.c
Normal file
192
sdk/software/examples/dhrystone/dhry_2.c
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
****************************************************************************
|
||||
*
|
||||
* "DHRYSTONE" Benchmark Program
|
||||
* -----------------------------
|
||||
*
|
||||
* Version: C, Version 2.1
|
||||
*
|
||||
* File: dhry_2.c (part 3 of 3)
|
||||
*
|
||||
* Date: May 25, 1988
|
||||
*
|
||||
* Author: Reinhold P. Weicker
|
||||
*
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "dhry.h"
|
||||
|
||||
#ifndef REG
|
||||
#define REG
|
||||
/* REG becomes defined as empty */
|
||||
/* i.e. no register variables */
|
||||
#endif
|
||||
|
||||
extern int Int_Glob;
|
||||
extern char Ch_1_Glob;
|
||||
|
||||
|
||||
Proc_6 (Enum_Val_Par, Enum_Ref_Par)
|
||||
/*********************************/
|
||||
/* executed once */
|
||||
/* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
|
||||
|
||||
Enumeration Enum_Val_Par;
|
||||
Enumeration *Enum_Ref_Par;
|
||||
{
|
||||
*Enum_Ref_Par = Enum_Val_Par;
|
||||
if (! Func_3 (Enum_Val_Par))
|
||||
/* then, not executed */
|
||||
*Enum_Ref_Par = Ident_4;
|
||||
switch (Enum_Val_Par)
|
||||
{
|
||||
case Ident_1:
|
||||
*Enum_Ref_Par = Ident_1;
|
||||
break;
|
||||
case Ident_2:
|
||||
if (Int_Glob > 100)
|
||||
/* then */
|
||||
*Enum_Ref_Par = Ident_1;
|
||||
else *Enum_Ref_Par = Ident_4;
|
||||
break;
|
||||
case Ident_3: /* executed */
|
||||
*Enum_Ref_Par = Ident_2;
|
||||
break;
|
||||
case Ident_4: break;
|
||||
case Ident_5:
|
||||
*Enum_Ref_Par = Ident_3;
|
||||
break;
|
||||
} /* switch */
|
||||
} /* Proc_6 */
|
||||
|
||||
|
||||
Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref)
|
||||
/**********************************************/
|
||||
/* executed three times */
|
||||
/* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */
|
||||
/* Int_Par_Ref becomes 7 */
|
||||
/* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
|
||||
/* Int_Par_Ref becomes 17 */
|
||||
/* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
|
||||
/* Int_Par_Ref becomes 18 */
|
||||
One_Fifty Int_1_Par_Val;
|
||||
One_Fifty Int_2_Par_Val;
|
||||
One_Fifty *Int_Par_Ref;
|
||||
{
|
||||
One_Fifty Int_Loc;
|
||||
|
||||
Int_Loc = Int_1_Par_Val + 2;
|
||||
*Int_Par_Ref = Int_2_Par_Val + Int_Loc;
|
||||
} /* Proc_7 */
|
||||
|
||||
|
||||
Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val)
|
||||
/*********************************************************************/
|
||||
/* executed once */
|
||||
/* Int_Par_Val_1 == 3 */
|
||||
/* Int_Par_Val_2 == 7 */
|
||||
Arr_1_Dim Arr_1_Par_Ref;
|
||||
Arr_2_Dim Arr_2_Par_Ref;
|
||||
int Int_1_Par_Val;
|
||||
int Int_2_Par_Val;
|
||||
{
|
||||
REG One_Fifty Int_Index;
|
||||
REG One_Fifty Int_Loc;
|
||||
|
||||
Int_Loc = Int_1_Par_Val + 5;
|
||||
Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
|
||||
Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
|
||||
Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
|
||||
for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
|
||||
Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
|
||||
Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
|
||||
Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
|
||||
Int_Glob = 5;
|
||||
} /* Proc_8 */
|
||||
|
||||
|
||||
Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val)
|
||||
/*************************************************/
|
||||
/* executed three times */
|
||||
/* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */
|
||||
/* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */
|
||||
/* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */
|
||||
|
||||
Capital_Letter Ch_1_Par_Val;
|
||||
Capital_Letter Ch_2_Par_Val;
|
||||
{
|
||||
Capital_Letter Ch_1_Loc;
|
||||
Capital_Letter Ch_2_Loc;
|
||||
|
||||
Ch_1_Loc = Ch_1_Par_Val;
|
||||
Ch_2_Loc = Ch_1_Loc;
|
||||
if (Ch_2_Loc != Ch_2_Par_Val)
|
||||
/* then, executed */
|
||||
return (Ident_1);
|
||||
else /* not executed */
|
||||
{
|
||||
Ch_1_Glob = Ch_1_Loc;
|
||||
return (Ident_2);
|
||||
}
|
||||
} /* Func_1 */
|
||||
|
||||
|
||||
Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref)
|
||||
/*************************************************/
|
||||
/* executed once */
|
||||
/* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
|
||||
/* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
|
||||
|
||||
Str_30 Str_1_Par_Ref;
|
||||
Str_30 Str_2_Par_Ref;
|
||||
{
|
||||
REG One_Thirty Int_Loc;
|
||||
Capital_Letter Ch_Loc;
|
||||
|
||||
Int_Loc = 2;
|
||||
while (Int_Loc <= 2) /* loop body executed once */
|
||||
if (Func_1 (Str_1_Par_Ref[Int_Loc],
|
||||
Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
|
||||
/* then, executed */
|
||||
{
|
||||
Ch_Loc = 'A';
|
||||
Int_Loc += 1;
|
||||
} /* if, while */
|
||||
if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
|
||||
/* then, not executed */
|
||||
Int_Loc = 7;
|
||||
if (Ch_Loc == 'R')
|
||||
/* then, not executed */
|
||||
return (true);
|
||||
else /* executed */
|
||||
{
|
||||
if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
|
||||
/* then, not executed */
|
||||
{
|
||||
Int_Loc += 7;
|
||||
Int_Glob = Int_Loc;
|
||||
return (true);
|
||||
}
|
||||
else /* executed */
|
||||
return (false);
|
||||
} /* if Ch_Loc */
|
||||
} /* Func_2 */
|
||||
|
||||
|
||||
Boolean Func_3 (Enum_Par_Val)
|
||||
/***************************/
|
||||
/* executed once */
|
||||
/* Enum_Par_Val == Ident_3 */
|
||||
Enumeration Enum_Par_Val;
|
||||
{
|
||||
Enumeration Enum_Loc;
|
||||
|
||||
Enum_Loc = Enum_Par_Val;
|
||||
if (Enum_Loc == Ident_3)
|
||||
/* then, executed */
|
||||
return (true);
|
||||
else /* not executed */
|
||||
return (false);
|
||||
} /* Func_3 */
|
||||
|
||||
35
sdk/software/examples/fireye/A0/A0.c
Normal file
35
sdk/software/examples/fireye/A0/A0.c
Normal file
@@ -0,0 +1,35 @@
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbfe001e0; //UART16550的虚地址
|
||||
unsigned long CONFREG_UART_BASE = 0xbfafff10; //CONFREG模拟UART的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbfafe000; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 100000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
int A0_n = 10000;
|
||||
int A0_k = 20;
|
||||
int data[20] = {207, 47, 368, 668, 655, 560, 8, 820, 11, 723, 396, 310, 268, 572, 45, 84, 229, 5, 92, 475};
|
||||
#define LOOP 1
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define KN 10000
|
||||
|
||||
int pos[KN] = {1};
|
||||
|
||||
int A0_max(int a, int b) { return a > b ? a : b; }
|
||||
|
||||
int main() {
|
||||
pos[0] = 0;
|
||||
|
||||
int ans = 0;
|
||||
for(int i = 0; i < A0_k; i++) {
|
||||
int x = data[i];
|
||||
for(int j = x; j <= A0_n; j += x) pos[j] ^= 1;
|
||||
int tmp = 0;
|
||||
for(int j = 1; j <= A0_n; j++) tmp += pos[j];
|
||||
ans = A0_max(ans, tmp);
|
||||
}
|
||||
|
||||
printf("%d\n", ans);
|
||||
return (ans == 3367) ? 0 : 1;
|
||||
}
|
||||
14
sdk/software/examples/fireye/A0/Makefile
Normal file
14
sdk/software/examples/fireye/A0/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
TARGET = fireye_A0
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../../bsp
|
||||
GCC_DIR=../../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../../toolchains/picolibc
|
||||
include ../../../bsp/common.mk
|
||||
61
sdk/software/examples/fireye/B2/B2.c
Normal file
61
sdk/software/examples/fireye/B2/B2.c
Normal file
@@ -0,0 +1,61 @@
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbfe001e0; //UART16550的虚地址
|
||||
unsigned long CONFREG_UART_BASE = 0xbfafff10; //CONFREG模拟UART的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbfafe000; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 100000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
int B2_n = 100;
|
||||
int L[100] = {48, 47, 40, 40, 36, 31, 25, 25, 25, 24, 14, 13, 13, 10, 10, 10, 10, 10, 10, 8, 5, 5, 5, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 21, 21, 21, 21, 21, 23, 23, 23, 23, 26, 29, 29, 32, 32, 32, 32, 33, 33, 33, 33, 38, 38, 38, 38, 38, 38, 38, 39, 40, 40, 40, 42, 43, 48};
|
||||
int R[100] = {48, 48, 53, 53, 53, 54, 55, 57, 59, 66, 66, 66, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 96, 96, 96, 96, 96, 96, 96, 96, 95, 95, 95, 95, 94, 94, 93, 93, 93, 92, 92, 89, 89, 83, 80, 79, 78, 77, 77, 76, 76, 71, 71, 71, 71, 70, 70, 69, 69, 69, 68, 57, 51, 48};
|
||||
|
||||
#define LOOP 2
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define KN 100
|
||||
|
||||
int log_2(int x) { int ans = 0; while(x >>= 1) ans++; return ans; }
|
||||
int B2_max(int a, int b) { return a > b ? a : b; }
|
||||
int B2_min(int a, int b) { return a < b ? a : b; }
|
||||
|
||||
int query(int d[][KN], int l, int r, int maxx) {
|
||||
int t = log_2(r - l + 1);
|
||||
if (maxx) return B2_max(d[t][l], d[t][r - (1 << t) + 1]);
|
||||
return B2_min(d[t][l], d[t][r - (1 << t) + 1]);
|
||||
}
|
||||
|
||||
void init(int d[][KN], int a[], int len, int maxx) {
|
||||
for (int i = 0; i < len; i++) d[0][i] = a[i];
|
||||
int t = 1;
|
||||
for (int i = 1; t <= len; i++) {
|
||||
for (int j = 0; j + t < len; j++)
|
||||
if (maxx)d[i][j] = B2_max(d[i - 1][j], d[i - 1][j + t]);
|
||||
else d[i][j] = B2_min(d[i - 1][j], d[i - 1][j + t]);
|
||||
t <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int dl[20][KN], dr[20][KN];
|
||||
|
||||
init(dl, L, B2_n, 1);
|
||||
init(dr, R, B2_n, 0);
|
||||
|
||||
int ans;
|
||||
for (int var = 0; var < LOOP; var++) {
|
||||
ans = 1;
|
||||
for (int i = 1; i <= B2_n; i++) {
|
||||
int l = ans, r = B2_n - i + 1;
|
||||
while (l <= r) {
|
||||
int mid = l + r >> 1;
|
||||
if (query(dr, i - 1, i + mid - 2, 0) - query(dl, i - 1, i + mid - 2, 1) + 1 >= mid) {
|
||||
ans = B2_max(ans, mid); l = mid + 1;
|
||||
} else r = mid - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d\n", ans);
|
||||
return (ans == 64) ? 0 : 1;
|
||||
}
|
||||
14
sdk/software/examples/fireye/B2/Makefile
Normal file
14
sdk/software/examples/fireye/B2/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
TARGET = fireye_B2
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../../bsp
|
||||
GCC_DIR=../../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../../toolchains/picolibc
|
||||
include ../../../bsp/common.mk
|
||||
74
sdk/software/examples/fireye/C0/C0.c
Normal file
74
sdk/software/examples/fireye/C0/C0.c
Normal file
@@ -0,0 +1,74 @@
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbfe001e0; //UART16550的虚地址
|
||||
unsigned long CONFREG_UART_BASE = 0xbfafff10; //CONFREG模拟UART的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbfafe000; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 100000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
int C0_n = 2, A = 50, C0_m = 2, B = 50;
|
||||
char C0_data0[50][3] = {"of", "to", "in", "is", "it", "on", "be", "as", "at", "by", "he", "or", "an", "we", "up", "so", "if", "do", "no", "me", "my", "go", "er", "us", "am", "oh", "de", "mm", "et", "al", "la", "ah", "ha", "eh", "ad", "ya", "en", "re", "ye", "ex", "yo", "ma", "na", "ta", "ed", "sh", "ho", "um", "em", "un"};
|
||||
char C0_data1[50][3] = {"lo", "wo", "hi", "li", "ti", "ne", "ba", "pa", "si", "id", "mi", "mo", "fe", "el", "ox", "ab", "ar", "es", "ow", "pe", "bo", "oi", "op", "fa", "uh", "bi", "pi", "mu", "hm", "ay", "xi", "ki", "nu", "os", "aa", "ai", "ag", "ae", "ut", "aw", "oy", "ka", "ax", "od", "qi", "om", "jo", "za", "ef", "oe"};
|
||||
|
||||
#define LOOP 2
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define N 100
|
||||
|
||||
int mpN[6][6], mpM[6][6];
|
||||
int ans;
|
||||
|
||||
struct Trie {
|
||||
int ch[N][26];
|
||||
int tot;
|
||||
} t[2] = {{{1}, 0}, {{1}, 0}};
|
||||
|
||||
void insert(struct Trie *t, char *s) {
|
||||
int x = 0;
|
||||
for (int i = 0; s[i] != '\0'; i++) {
|
||||
if (!t->ch[x][s[i] - 'a'])
|
||||
t->ch[x][s[i] - 'a'] = ++t->tot;
|
||||
x = t->ch[x][s[i] - 'a'];
|
||||
}
|
||||
}
|
||||
|
||||
void dfs(int x, int y) {
|
||||
if (x == C0_n + 1) {
|
||||
++ans;
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 26; i++) {
|
||||
int lastN = mpN[x - 1][y], lastM = mpM[x][y - 1];
|
||||
int nx = t[0].ch[lastN][i], ny = t[1].ch[lastM][i];
|
||||
if (!(nx && ny)) continue;
|
||||
mpN[x][y] = nx;
|
||||
mpM[x][y] = ny;
|
||||
|
||||
nx = x, ny = y + 1;
|
||||
if (ny > C0_m) ++nx, ny = 1;
|
||||
dfs(nx, ny);
|
||||
}
|
||||
}
|
||||
|
||||
void run() {
|
||||
for (int i = 0; i < A; i++) {
|
||||
insert(&t[0], C0_data0[i]);
|
||||
}
|
||||
for (int i = 0; i < B; i++) {
|
||||
insert(&t[1], C0_data1[i]);
|
||||
}
|
||||
for (int i = 0; i < LOOP; i++) {
|
||||
ans = 0;
|
||||
dfs(1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
t[0].ch[0][0] = 0;
|
||||
t[1].ch[0][0] = 0;
|
||||
|
||||
run();
|
||||
printf("%d\n", ans);
|
||||
|
||||
return (ans == 62) ? 0 : 1;
|
||||
}
|
||||
14
sdk/software/examples/fireye/C0/Makefile
Normal file
14
sdk/software/examples/fireye/C0/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
TARGET = fireye_C0
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../../bsp
|
||||
GCC_DIR=../../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../../toolchains/picolibc
|
||||
include ../../../bsp/common.mk
|
||||
76
sdk/software/examples/fireye/D1/D1.c
Normal file
76
sdk/software/examples/fireye/D1/D1.c
Normal file
@@ -0,0 +1,76 @@
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbfe001e0; //UART16550的虚地址
|
||||
unsigned long CONFREG_UART_BASE = 0xbfafff10; //CONFREG模拟UART的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbfafe000; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 100000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
int x = 1000, y = 1000, D1_n = 492;
|
||||
int D1_data0[492] = {595, 982, 328, 543, 646, 541, 484, 344, 862, 393, 378, 997, 699, 264, 128, 565, 582, 136, 768, 872, 967, 769, 979, 439, 892, 174, 779, 339, 520, 175, 931, 606, 146, 430, 661, 877, 950, 103, 563, 903, 681, 921, 924, 186, 20, 591, 953, 962, 253, 882, 141, 413, 845, 337, 465, 735, 659, 750, 821, 853, 100, 521, 16, 740, 580, 468, 562, 206, 476, 682, 68, 634, 126, 895, 947, 696, 246, 511, 38, 356, 319, 291, 519, 367, 164, 279, 330, 560, 137, 350, 564, 51, 332, 256, 657, 455, 459, 242, 537, 23, 526, 714, 10, 412, 630, 287, 410, 840, 987, 99, 98, 311, 235, 198, 588, 977, 282, 6, 841, 719, 598, 259, 207, 255, 720, 664, 766, 501, 671, 323, 937, 949, 392, 14, 739, 217, 228, 592, 957, 556, 406, 376, 94, 518, 669, 315, 223, 22, 483, 625, 780, 990, 748, 172, 33, 884, 341, 972, 426, 831, 529, 724, 787, 241, 628, 744, 461, 12, 763, 850, 973, 247, 403, 195, 790, 290, 856, 764, 331, 796, 69, 677, 754, 102, 355, 804, 738, 46, 920, 566, 795, 989, 803, 514, 742, 364, 125, 629, 889, 570, 776, 161, 24, 885, 601, 948, 822, 761, 805, 495, 326, 871, 911, 952, 651, 153, 858, 506, 913, 919, 799, 236, 737, 559, 249, 965, 729, 208, 202, 615, 833, 417, 340, 440, 834, 257, 741, 700, 122, 158, 452, 116, 215, 755, 851, 283, 276, 618, 36, 819, 133, 600, 645, 148, 583, 983, 115, 929, 313, 63, 405, 181, 534, 785, 767, 945, 351, 303, 797, 415, 930, 204, 400, 467, 727, 690, 854, 268, 789, 728, 602, 307, 976, 360, 444, 552, 144, 41, 384, 706, 905, 899, 828, 510, 694, 245, 62, 670, 425, 597, 394, 551, 607, 273, 117, 42, 839, 500, 686, 879, 986, 423, 486, 532, 745, 294, 65, 544, 916, 286, 284, 120, 383, 170, 179, 868, 818, 90, 616, 936, 823, 807, 568, 233, 447, 557, 722, 723, 297, 448, 656, 642, 266, 433, 808, 830, 280, 361, 185, 708, 293, 545, 225, 956, 567, 229, 917, 398, 673, 718, 281, 586, 60, 5, 352, 270, 149, 594, 775, 676, 458, 436, 2, 528, 451, 244, 975, 366, 162, 93, 298, 274, 810, 852, 37, 131, 826, 631, 349, 701, 784, 915, 89, 34, 814, 512, 372, 497, 316, 912, 209, 614, 231, 189, 984, 132, 407, 946, 308, 301, 166, 83, 58, 357, 914, 427, 44, 715, 434, 968, 887, 7, 505, 396, 214, 420, 674, 620, 477, 792, 760, 925, 961, 666, 991, 944, 637, 542, 698, 442, 865, 110, 730, 933, 875, 498, 783, 234, 765, 399, 88, 704, 535, 707, 18, 992, 445, 716, 310, 891, 32, 277, 824, 938, 751, 91, 391, 675, 385, 82, 842, 70, 324, 612, 558, 112, 581, 359, 752, 999, 424, 832, 782, 299, 288, 746, 438, 599, 414, 487, 201, 464};
|
||||
int D1_data1[492] = {29, 951, 39, 276, 380, 861, 357, 324, 624, 363, 758, 792, 233, 752, 950, 894, 215, 23, 525, 414, 933, 547, 364, 155, 256, 953, 749, 833, 344, 792, 614, 633, 325, 744, 872, 239, 317, 77, 29, 20, 545, 601, 168, 369, 124, 760, 727, 515, 49, 7, 292, 631, 384, 262, 665, 430, 403, 304, 458, 541, 314, 998, 324, 578, 27, 607, 245, 38, 851, 874, 478, 900, 370, 175, 514, 13, 845, 717, 67, 723, 901, 828, 936, 891, 72, 952, 762, 536, 985, 488, 229, 81, 909, 613, 840, 66, 901, 79, 813, 59, 212, 502, 985, 317, 112, 161, 941, 880, 150, 599, 730, 378, 847, 367, 901, 155, 982, 340, 97, 957, 78, 138, 359, 29, 950, 578, 626, 548, 80, 703, 674, 80, 869, 941, 324, 893, 76, 263, 836, 365, 453, 270, 507, 530, 865, 982, 493, 868, 148, 869, 675, 470, 440, 512, 797, 929, 897, 224, 619, 666, 251, 485, 707, 680, 281, 990, 435, 675, 189, 463, 743, 489, 662, 223, 155, 25, 476, 862, 870, 284, 445, 191, 297, 181, 900, 288, 249, 371, 533, 929, 159, 30, 89, 986, 33, 547, 178, 949, 964, 130, 700, 840, 124, 242, 376, 879, 746, 295, 450, 784, 844, 753, 38, 434, 403, 439, 598, 713, 480, 589, 742, 234, 650, 922, 3, 771, 16, 498, 371, 956, 747, 848, 30, 769, 483, 810, 683, 600, 981, 168, 127, 325, 324, 255, 446, 33, 281, 786, 896, 383, 387, 823, 302, 314, 437, 102, 629, 272, 478, 419, 375, 549, 425, 27, 410, 532, 44, 988, 198, 187, 504, 37, 837, 257, 338, 660, 124, 978, 813, 52, 521, 329, 388, 855, 729, 117, 314, 769, 127, 191, 292, 21, 895, 37, 718, 250, 514, 779, 326, 577, 306, 757, 34, 363, 786, 809, 153, 70, 714, 610, 575, 213, 611, 20, 958, 615, 985, 251, 181, 7, 569, 307, 91, 996, 93, 105, 143, 944, 864, 546, 444, 453, 318, 514, 383, 546, 81, 128, 780, 35, 521, 714, 288, 14, 622, 621, 701, 445, 187, 246, 593, 674, 331, 38, 120, 898, 366, 429, 291, 221, 553, 59, 326, 558, 565, 393, 991, 549, 232, 80, 935, 330, 491, 632, 478, 58, 396, 183, 205, 769, 236, 537, 92, 516, 379, 90, 796, 248, 418, 230, 368, 666, 608, 993, 219, 700, 456, 294, 917, 482, 613, 662, 390, 2, 947, 11, 81, 607, 898, 855, 18, 857, 310, 811, 666, 940, 359, 199, 148, 476, 315, 890, 310, 968, 979, 174, 895, 632, 597, 759, 255, 1, 133, 763, 788, 136, 256, 335, 325, 766, 901, 280, 254, 688, 731, 793, 996, 288, 80, 80, 842, 584, 951, 600, 818, 323, 303, 303, 318, 807, 47, 864, 63, 140, 450, 231, 905, 200, 247, 725, 4, 714, 122, 298, 60, 547, 433, 328, 666, 606, 143, 643, 689, 716, 425, 737, 594, 255, 243, 931, 537, 358};
|
||||
#define LOOP 2
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAXN 10000
|
||||
|
||||
int in[MAXN] = {1}, out[MAXN] = {1};
|
||||
int mn[MAXN] = {1}, mx [MAXN] = {1};
|
||||
|
||||
int D1_max(int a, int b) { return a > b ? a : b; }
|
||||
int D1_min(int a, int b) { return a < b ? a : b; }
|
||||
|
||||
int main() {
|
||||
int ans;
|
||||
|
||||
for (int l = 0; l < LOOP; l++) {
|
||||
memset(mn, -1, (D1_max(x, y) + 1) * sizeof(int));
|
||||
memset(mx, -1, (D1_max(x, y) + 1) * sizeof(int));
|
||||
memset(in, 0, (D1_max(x, y) + 1) * sizeof(int));
|
||||
memset(out, 0, (D1_max(x, y) + 1) * sizeof(int));
|
||||
|
||||
int a, b;
|
||||
for (int i = 0; i < D1_n; i++) {
|
||||
a = D1_data0[i];
|
||||
b = D1_data1[i];
|
||||
if (mn[a] == -1)
|
||||
mn[a] = b;
|
||||
else
|
||||
mn[a] = D1_min(mn[a], b);
|
||||
mx[a] = D1_max(mx[a], b);
|
||||
}
|
||||
|
||||
int reduce = 0;
|
||||
int down = 0;
|
||||
int sum = 0;
|
||||
|
||||
for (int i = 0; i < y + 1; i++) {
|
||||
if (mx[i] != -1){
|
||||
in[mx[i]]++;
|
||||
|
||||
out[mn[i]]++;
|
||||
sum += mn[i];
|
||||
down++;
|
||||
}
|
||||
}
|
||||
|
||||
ans = 0x7fffffff;
|
||||
int up = 0, upsum = 0;
|
||||
for (int p = y + 1; p >= 0; p--){
|
||||
if (in[p] > 0){
|
||||
up += in[p];
|
||||
upsum += in[p] * p;
|
||||
}
|
||||
if (out[p] > 0){
|
||||
down -= out[p];
|
||||
sum -= out[p] * p;
|
||||
}
|
||||
int df = 2 * ((upsum - up * p) + (down * p - sum));
|
||||
ans = D1_min(ans, df);
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d\n", ans + x - 1);
|
||||
return (ans + x - 1 == 253649) ? 0 : 1;
|
||||
}
|
||||
14
sdk/software/examples/fireye/D1/Makefile
Normal file
14
sdk/software/examples/fireye/D1/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
TARGET = fireye_D1
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../../bsp
|
||||
GCC_DIR=../../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../../toolchains/picolibc
|
||||
include ../../../bsp/common.mk
|
||||
122
sdk/software/examples/fireye/I2/I2.c
Normal file
122
sdk/software/examples/fireye/I2/I2.c
Normal file
@@ -0,0 +1,122 @@
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbfe001e0; //UART16550的虚地址
|
||||
unsigned long CONFREG_UART_BASE = 0xbfafff10; //CONFREG模拟UART的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbfafe000; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 100000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
int I2_m = 19, I2_n = 32;
|
||||
char s[32][21] = {" ###################", " #.................#", " #.###############.#", " #.###############.#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.##..............#", " #.###############.#", " #.###############.#", " #.................#", " ###################"};
|
||||
int vis[32][19] = {1};
|
||||
|
||||
#define LOOP 10
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int dd[8][2] = {{-1, 0}, {-1, -1}, {-1, 1}, {0, 1}, {0, -1}, {1, 0}, {1, -1}, {1, 1}};
|
||||
int abc[3][15] = {{1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1},
|
||||
{1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1},
|
||||
{1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1}
|
||||
};
|
||||
int add1[20], add2[20];
|
||||
|
||||
int check(int x, int y, int I2_n, int I2_m, char cur) {
|
||||
for (int i = x; i < x + I2_n; i++)
|
||||
for (int j = y; j < y + I2_m; j++)
|
||||
if (s[i][j] != cur || vis[i][j])return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int find(int stx, int sty, int x, int y, int cur) {
|
||||
add1[0] = 0, add1[1] = x, add1[2] = x + y;
|
||||
for (int i = 3; i < 15; i++)add1[i] = add1[i % 3];
|
||||
add2[0] = 0, add2[3] = x, add2[6] = x + y, add2[9] = 2 * x + y, add2[12] = 2 * x + 2 * y;
|
||||
for (int i = 0; i < 5; i++)
|
||||
for (int j = 1; j < 3; j++)add2[3 * i + j] = add2[3 * i + j - 1];
|
||||
|
||||
for (int i = 0; i < 15; i++) {
|
||||
int addn = 0, addm = 0;
|
||||
if (i / 3 % 2 == 0)addn = x; else addn = y;
|
||||
if (i % 3 % 2 == 0)addm = x; else addm = y;
|
||||
|
||||
char findchar = '.';
|
||||
if (abc[cur][i])findchar = '#';
|
||||
if (check(stx + add2[i], sty + add1[i], addn, addm, findchar)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
int ansa = 0, ansb = 0, ansc = 0;
|
||||
|
||||
for (int l = 0; l < LOOP; l++) {
|
||||
|
||||
ansa = ansb = ansc = 0;
|
||||
memset(vis, 0, sizeof(vis));
|
||||
|
||||
for (int i = 2; i <= I2_n - 1; i++)
|
||||
for (int j = 2; j <= I2_m - 1; j++)
|
||||
if (s[i][j] == '#') {
|
||||
int gg = 0;
|
||||
for (int k = 0; k < 8; k++)
|
||||
if (s[i + dd[k][0]][j + dd[k][1]] == '#') {
|
||||
gg++;
|
||||
break;
|
||||
}
|
||||
if (!gg)s[i][j] = '.';
|
||||
}
|
||||
|
||||
for (int i = 2; i <= I2_n - 1; i++)
|
||||
for (int j = 2; j <= I2_m - 2; j++)
|
||||
if (s[i][j] == '.' && s[i][j + 1] == '#' && !vis[i][j]) {
|
||||
int a = 1, b = 1;
|
||||
for (int k = j + 2; k <= I2_m - 2; k++)
|
||||
if (s[i][k] == '#')a++;
|
||||
else break;
|
||||
for (int k = i + 1; k <= I2_n - 2; k++)
|
||||
if (s[k][j + 1] == '#')b++;
|
||||
else break;
|
||||
|
||||
int x = 2 * a - b, y = 2 * b - 3 * a;
|
||||
if (x <= 0 || y <= 0)continue;
|
||||
|
||||
int gg = 0;
|
||||
for (int k = j; k <= j + a + 1; k++)
|
||||
if (s[i - 1][k] == '#' || s[i + b][k] == '#') {
|
||||
gg++;
|
||||
break;
|
||||
}
|
||||
if (gg)continue;
|
||||
for (int k = i; k <= i + b - 1; k++)
|
||||
if (s[k][j] == '#' || s[k][j + a + 1] == '#') {
|
||||
gg++;
|
||||
break;
|
||||
}
|
||||
if (gg)continue;
|
||||
|
||||
int cur = 0;
|
||||
if (s[i][j + x + 1] == '#' && s[i + x + y][j + x + 1] == '#' && s[i + 2 * (x + y)][j + x + 1] == '.')cur = 1;
|
||||
if (s[i][j + x + 1] == '#' && s[i + x + y][j + x + 1] == '#' && s[i + 2 * (x + y)][j + x + 1] == '#')cur = 2;
|
||||
if (s[i][j + x + 1] == '#' && s[i + x + y][j + x + 1] == '.' && s[i + 2 * (x + y)][j + x + 1] == '#')cur = 3;
|
||||
|
||||
if (!cur)continue;
|
||||
|
||||
if (find(i, j + 1, x, y, cur - 1)) {
|
||||
for (int visx = i - 1; visx <= i + b; visx++)
|
||||
for (int visy = j; visy <= j + a + 1; visy++)
|
||||
vis[visx][visy]++;
|
||||
if (cur == 1)ansa++;
|
||||
else if (cur == 2)ansb++;
|
||||
else ansc++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d %d %d\n", ansa, ansb, ansc);
|
||||
return (ansa == 0 && ansb == 0 && ansc == 1) ? 0 : 1;
|
||||
}
|
||||
14
sdk/software/examples/fireye/I2/Makefile
Normal file
14
sdk/software/examples/fireye/I2/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
TARGET = fireye_I2
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
#根据SIMU宏选择串口波特率,0:FPGA上板;1:仿真
|
||||
CFLAGS += -DSIMU=0
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../../bsp
|
||||
GCC_DIR=../../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../../toolchains/picolibc
|
||||
include ../../../bsp/common.mk
|
||||
11
sdk/software/examples/hello_world/Makefile
Normal file
11
sdk/software/examples/hello_world/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
TARGET = hello_world
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../bsp
|
||||
GCC_DIR=../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../toolchains/picolibc
|
||||
include ../../bsp/common.mk
|
||||
36
sdk/software/examples/hello_world/main.c
Normal file
36
sdk/software/examples/hello_world/main.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbf000000; //UART16550的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbf20f100; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 50000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
#define CPSIZE 12
|
||||
char src[CPSIZE] = "this is src";
|
||||
char dst[CPSIZE] = "this is dst";
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int a = 100;
|
||||
float b = 3.2564;
|
||||
double c = 5478.47563;
|
||||
char *str;
|
||||
|
||||
printf("Hello Loongarch32r!\n");
|
||||
printf("a = %d\n", a);
|
||||
printf("b = %f\n", b);
|
||||
printf("c = %lf\n", c);
|
||||
|
||||
str = (char *)malloc(6);
|
||||
strcpy(str, "ABCDE");
|
||||
printf("String = %s, Address = 0x%x\n", str, str);
|
||||
|
||||
memcpy(dst, src, CPSIZE);
|
||||
printf("%s\n", dst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
11
sdk/software/examples/int_test/Makefile
Normal file
11
sdk/software/examples/int_test/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
TARGET = int_test
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../bsp
|
||||
GCC_DIR=../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../toolchains/picolibc
|
||||
include ../../bsp/common.mk
|
||||
96
sdk/software/examples/int_test/main.c
Normal file
96
sdk/software/examples/int_test/main.c
Normal file
@@ -0,0 +1,96 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common_func.h"
|
||||
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbf000000; //UART16550的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbf20f100; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 50000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
|
||||
int Ball_x = 400;
|
||||
int Ball_y = 100;
|
||||
int Ball_r = 5;
|
||||
|
||||
int Plane_x = 400;
|
||||
int Plane_y = 400;
|
||||
int Plane_l = 100;
|
||||
int Plane_w = 5;
|
||||
|
||||
int simu_flag;
|
||||
volatile unsigned char int_flag;
|
||||
|
||||
void Timer_IntrHandler(void);
|
||||
void Button_IntrHandler(unsigned char button_state);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int_flag = 0;
|
||||
DVI_Draw_Rect(Plane_x,Plane_y,Plane_l,Plane_w);
|
||||
DVI_Draw_SQU(Ball_x,Ball_y,Ball_r);
|
||||
|
||||
simu_flag = RegRead(0xbf20f500);
|
||||
RegWrite(0xbf20f004,0x0f);//edge
|
||||
RegWrite(0xbf20f008,0x1f);//pol
|
||||
RegWrite(0xbf20f00c,0x1f);//clr
|
||||
RegWrite(0xbf20f000,0x1f);//en
|
||||
if(simu_flag){
|
||||
RegWrite(0xbf20f104,5000);//timercmp 0.1ms
|
||||
}
|
||||
else{
|
||||
RegWrite(0xbf20f104,50000000);//timercmp 1s
|
||||
}
|
||||
RegWrite(0xbf20f108,0x1);//timeren
|
||||
|
||||
while(int_flag == 0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HWI0_IntrHandler(void)
|
||||
{
|
||||
unsigned int int_state;
|
||||
int_state = RegRead(0xbf20f014);
|
||||
|
||||
if((int_state & 0x10) == 0x10){
|
||||
Timer_IntrHandler();
|
||||
}
|
||||
else if(int_state & 0xf){
|
||||
Button_IntrHandler(int_state & 0xf);
|
||||
}
|
||||
}
|
||||
|
||||
void Timer_IntrHandler(void)
|
||||
{
|
||||
RegWrite(0xbf20f108,0);//timeren
|
||||
RegWrite(0xbf20f108,1);//timeren
|
||||
printf("timer int\n");
|
||||
}
|
||||
|
||||
void Button_IntrHandler(unsigned char button_state)
|
||||
{
|
||||
if((button_state & 0b1000) == 0b1000){
|
||||
printf("button4 int\n");
|
||||
int_flag = 1;
|
||||
RegWrite(0xbf20f00c,0x8);//clr
|
||||
}
|
||||
else if((button_state & 0b0100) == 0b0100){
|
||||
printf("button3 int\n");
|
||||
RegWrite(0xbf20f00c,0x4);//clr
|
||||
}
|
||||
else if((button_state & 0b0010) == 0b0010){
|
||||
printf("button2 int\n");
|
||||
RegWrite(0xbf20f00c,0x2);//clr
|
||||
}
|
||||
else if((button_state & 0b0001) == 0b0001){
|
||||
printf("button1 int\n");
|
||||
RegWrite(0xbf20f00c,0x1);//clr
|
||||
}
|
||||
}
|
||||
179
sdk/software/examples/lenet/AccelConvFuncs.c
Normal file
179
sdk/software/examples/lenet/AccelConvFuncs.c
Normal file
@@ -0,0 +1,179 @@
|
||||
#include "AccelConvFuncs.h"
|
||||
|
||||
void accel_conv_func(int8_t* d_i, int8_t* weight, int32_t* bias, int32_t* d_o, int8_t di_type,
|
||||
int height, int width, int padding, int channel, int out_channel,
|
||||
int kernel_width, int kernel_height, int with_relu) {
|
||||
accel_conf_t accel_conf;
|
||||
accel_conf.buf_size = di_type;
|
||||
accel_conf.weight_size = 0;
|
||||
accel_conf.padding = padding;
|
||||
accel_conf.stride = 1;
|
||||
accel_conf.kernel_height = kernel_height;
|
||||
accel_conf.kernel_width = kernel_width;
|
||||
|
||||
int size_mul = di_type == 0b10 ? 4 :
|
||||
di_type == 0b01 ? 2 : 1;
|
||||
int buf_mul = di_type == 0b10 ? 1 :
|
||||
di_type == 0b01 ? 2 : 4;
|
||||
|
||||
int del_h = kernel_height - 1;
|
||||
int del_w = (kernel_width - 1) * size_mul;
|
||||
|
||||
int size_sft = size_mul >> 1;
|
||||
int buf_sft = buf_mul >> 1;
|
||||
int width_i = width * size_mul;
|
||||
int height_o = (height - kernel_height + padding * 2) + 1;
|
||||
int width_o = ((width - kernel_width + padding * 2) + 1);
|
||||
|
||||
|
||||
int h_append = 0;
|
||||
int res_h = 0;
|
||||
for (int h = 0; h < height; h += h_append) {
|
||||
int h_eq_0 = h == 0;
|
||||
h_append = h_eq_0 ? MAX_BUF_HEIGHT : MAX_BUF_HEIGHT - del_h;
|
||||
int h_remain = height - h;
|
||||
int buf_h_end = h_remain <= h_append;
|
||||
int buf_h;
|
||||
int begin_h = h_eq_0 ? 0 : h - del_h;
|
||||
if (buf_h_end) {
|
||||
if (h_eq_0) buf_h = h_remain;
|
||||
else buf_h = h_remain + del_h;
|
||||
} else {
|
||||
buf_h = MAX_BUF_HEIGHT;
|
||||
}
|
||||
accel_conf.buf_height = buf_h - 1;
|
||||
int res_h_append = (buf_h - kernel_height + (h_eq_0 + buf_h_end) * padding) + 1;
|
||||
|
||||
int w_append = 0;
|
||||
int res_w = 0;
|
||||
for (int w = 0; w < width_i; w += w_append) {
|
||||
int w_eq_0 = w == 0;
|
||||
w_append = w_eq_0 ? MAX_BUF_WIDTH : MAX_BUF_WIDTH - del_w;
|
||||
int w_remain = width_i - w;
|
||||
int buf_w_end = w_remain <= w_append;
|
||||
int buf_w;
|
||||
int begin_w = w_eq_0 ? 0 : w - del_w;
|
||||
if (buf_w_end) {
|
||||
if (w_eq_0) {
|
||||
buf_w = w_remain;
|
||||
} else {
|
||||
buf_w = (w_remain + del_w);
|
||||
}
|
||||
} else {
|
||||
buf_w = MAX_BUF_WIDTH;
|
||||
}
|
||||
int padding_valid = (w_eq_0) |
|
||||
(buf_w_end << 1) |
|
||||
(h_eq_0 << 2) |
|
||||
(buf_h_end << 3);
|
||||
int buf_offset = width_i - buf_w;
|
||||
int res_w_append = ((buf_w >> size_sft) - kernel_width + (w_eq_0 + buf_w_end) * padding) + 1;
|
||||
int res_offset = (width_o - res_w_append) << size_sft;
|
||||
int res_buf_info = ((res_w_append - 1) << 16) | res_offset;
|
||||
inst_conf_offset(buf_offset, res_buf_info);
|
||||
|
||||
accel_conf.buf_width = buf_w - 1;
|
||||
accel_conf.padding_valid = padding_valid;
|
||||
for (int k = 0; k < channel; k++) {
|
||||
accel_conf.buf_refresh = 1;
|
||||
accel_conf.wadd = k != 0;
|
||||
for (int c = 0; c < out_channel; c += MAX_KERNEL_NUM) {
|
||||
int valid_kernel_num = c + MAX_KERNEL_NUM > out_channel ? out_channel - c : MAX_KERNEL_NUM;
|
||||
accel_conf.kernel_num = valid_kernel_num - 1;
|
||||
inst_conf_buf((uint32_t)&d_i[(k * height + begin_h) * width_i + begin_w], accel_conf.val);
|
||||
for (int vc = 0; vc < valid_kernel_num; vc++) {
|
||||
int ca = c + vc;
|
||||
inst_conf_res_addr(&d_o[(ca * height_o + res_h) * width_o + res_w], vc);
|
||||
|
||||
if (k == 0) {
|
||||
inst_conf_res_bias(bias[ca], vc);
|
||||
// for (int m = 0; m < res_h_append; m++) {
|
||||
// for (int n = 0; n < res_w_append; n++) {
|
||||
// d_o[(ca * height_o + res_h + m) * width_o + res_w + n] = bias[ca];
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
if (k == channel - 1 && with_relu) {
|
||||
inst_conv_relu(&weight[(k * out_channel + c) * kernel_height * kernel_width]);
|
||||
} else {
|
||||
inst_conv(&weight[(k * out_channel + c) * kernel_height * kernel_width]);
|
||||
}
|
||||
accel_conf.buf_refresh = 0;
|
||||
}
|
||||
}
|
||||
res_w += res_w_append;
|
||||
}
|
||||
res_h += res_h_append;
|
||||
}
|
||||
}
|
||||
|
||||
// height and width must align 2
|
||||
void accel_pool_func(int32_t* d_i, int32_t* d_o, int pool_mode, int channel, int height, int width) {
|
||||
accel_conf_t conf;
|
||||
conf.buf_refresh = 1;
|
||||
conf.wadd = 0;
|
||||
conf.padding_valid = 0;
|
||||
conf.weight_size = 2;
|
||||
conf.buf_size = 2;
|
||||
conf.kernel_width = 2;
|
||||
conf.kernel_height = 2;
|
||||
conf.stride = 2;
|
||||
conf.kernel_num = 0;
|
||||
conf.padding = 0;
|
||||
|
||||
int max_width_word = MAX_BUF_WIDTH >> 2;
|
||||
|
||||
// for (int i = 0; i < height; i++) {
|
||||
// for(int j = 0; j < width; j++) {
|
||||
// printf("%x ", d_i[i * width + j]);
|
||||
// }
|
||||
// printf("\n");
|
||||
// }
|
||||
|
||||
int width_o = width >> 1;
|
||||
int height_o = height >> 1;
|
||||
|
||||
for (int c = 0; c < channel; c++) {
|
||||
int h_append;
|
||||
int res_h = 0;
|
||||
for (int h = 0; h < height; h += h_append) {
|
||||
h_append = height - h < MAX_BUF_HEIGHT ? height - h : MAX_BUF_HEIGHT;
|
||||
int buf_h = h_append;
|
||||
conf.buf_height = buf_h - 1;
|
||||
int res_h_append = buf_h >> 1;
|
||||
|
||||
int w_append;
|
||||
int res_w = 0;
|
||||
for (int w = 0; w < width; w += w_append) {
|
||||
int w_remain = width - w;
|
||||
w_append = w_remain < max_width_word ? w_remain : max_width_word;
|
||||
int buf_w = w_append;
|
||||
conf.buf_width = (buf_w << 2) - 1;
|
||||
|
||||
inst_conf_buf((uint32_t)&d_i[(c * height + h) * width + w], conf.val);
|
||||
inst_conf_res_addr((uint32_t)&d_o[(c * height_o + res_h) * width_o + res_w], 0);
|
||||
int buf_offset = (width - buf_w) << 2;
|
||||
int res_w_append = (buf_w >> 1);
|
||||
int res_offset = (width_o - res_w_append) << 2;
|
||||
int res_buf_info = ((res_w_append - 1) << 16) | res_offset;
|
||||
inst_conf_offset(buf_offset, res_buf_info);
|
||||
inst_pool(pool_mode);
|
||||
|
||||
res_w += res_w_append;
|
||||
}
|
||||
res_h += res_h_append;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void accel_linear_func(int32_t* d_i, int8_t* weight, int32_t* bias,
|
||||
int32_t* output, int input_size, int output_size) {
|
||||
// 线性层的瓶颈在于访存,cpu可以处理计算
|
||||
for (int i = 0; i < output_size; i++) {
|
||||
output[i] = bias[i];
|
||||
for (int j = 0; j < input_size; j++) {
|
||||
output[i] += d_i[j] * weight[i * input_size + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
14
sdk/software/examples/lenet/AccelConvFuncs.h
Normal file
14
sdk/software/examples/lenet/AccelConvFuncs.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef __ACCEL__CONV__FUNCS__H__
|
||||
#define __ACCEL__CONV__FUNCS__H__
|
||||
#include "Accelop.h"
|
||||
|
||||
void accel_conv_func(int8_t* d_i, int8_t* weight, int32_t* bias, int32_t* d_o, int8_t di_type,
|
||||
int height, int width, int padding, int channel, int out_channel,
|
||||
int kernel_width, int kernel_height, int with_relu);
|
||||
|
||||
void accel_pool_func(int32_t* d_i, int32_t* d_o, int pool_mode, int channel, int height, int width);
|
||||
|
||||
void accel_linear_func(int32_t* d_i, int8_t* weight, int32_t* bias,
|
||||
int32_t* output, int input_size, int output_size);
|
||||
|
||||
#endif
|
||||
154
sdk/software/examples/lenet/Accelop.h
Normal file
154
sdk/software/examples/lenet/Accelop.h
Normal file
@@ -0,0 +1,154 @@
|
||||
#ifndef __ACCEL__OP__H__
|
||||
#define __ACCEL__OP__H__
|
||||
#include <stdint.h>
|
||||
// #define LACC_OP
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
uint32_t buf_refresh: 1;
|
||||
uint32_t wadd: 1;
|
||||
uint32_t padding_valid: 4;
|
||||
uint32_t weight_size: 2;
|
||||
uint32_t buf_size: 2;
|
||||
uint32_t kernel_width: 3;
|
||||
uint32_t kernel_height: 3;
|
||||
uint32_t buf_width: 5;
|
||||
uint32_t buf_height: 4;
|
||||
uint32_t stride: 2;
|
||||
uint32_t kernel_num: 3;
|
||||
uint32_t padding: 2;
|
||||
};
|
||||
uint32_t val;
|
||||
};
|
||||
}accel_conf_t;
|
||||
|
||||
#define MAX_KERNEL_NUM 3
|
||||
#define MAx_KERNEL_WIDTH 3
|
||||
#define MAX_KERNEL_HEIGHT 3
|
||||
#define MAX_BUF_WIDTH 32
|
||||
#define MAX_BUF_HEIGHT 8
|
||||
|
||||
void inst_conf_buf(uint32_t addr, uint32_t para) {
|
||||
#ifdef LACC_OP
|
||||
asm volatile (
|
||||
"lacc 0x0, $r0, %[addr], %[para], 0x0\n\t"
|
||||
::[addr]"r"(addr), [para]"r"(para)
|
||||
);
|
||||
#else
|
||||
asm volatile (
|
||||
"move $r5, %[addr]\n\t"
|
||||
"move $r6, %[para]\n\t"
|
||||
".word 0xc00018a0\n\t"
|
||||
::[addr]"r"(addr),[para]"r"(para)
|
||||
:"$r5", "$r6"
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
void inst_conf_res_addr(uint32_t waddr, uint32_t idx) {
|
||||
#ifdef LACC_OP
|
||||
asm volatile (
|
||||
"lacc 0x1, $r0, %[addr], %[idx], 0x5\n\t"
|
||||
::[addr]"r"(waddr), [idx]"r"(idx)
|
||||
);
|
||||
#else
|
||||
asm volatile (
|
||||
"move $r5, %[addr]\n\t"
|
||||
"move $r6, %[idx]\n\t"
|
||||
".word 0xc04298a0\n\t"
|
||||
::[addr]"r"(waddr), [idx]"r"(idx)
|
||||
:"$r5", "$r6"
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
void inst_conf_res_bias(uint32_t bias, uint32_t idx) {
|
||||
#ifdef LACC_OP
|
||||
asm volatile (
|
||||
"lacc 0x1, $r0, %[bias], %[idx], 0x2\n\t"
|
||||
::[bias]"r"(bias), [idx]"r"(idx)
|
||||
);
|
||||
#else
|
||||
asm volatile (
|
||||
"move $r5, %[addr]\n\t"
|
||||
"move $r6, %[idx]\n\t"
|
||||
".word 0xc04118a0\n\t"
|
||||
::[addr]"r"(bias), [idx]"r"(idx)
|
||||
:"$r5", "$r6"
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
typedef void (*inst_conv_ptr_t)(uint32_t);
|
||||
|
||||
void inst_conv(uint32_t weight_addr) {
|
||||
#ifdef LACC_OP
|
||||
asm volatile (
|
||||
"lacc 0x2, $r0, %[addr], $r0, 0x1\n\t"
|
||||
::[addr]"r"(weight_addr)
|
||||
);
|
||||
#else
|
||||
asm volatile (
|
||||
"move $r5, %[addr]\n\t"
|
||||
".word 0xc08080a0\n\t"
|
||||
::[addr]"r"(weight_addr)
|
||||
: "$r5"
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
void inst_conv_relu(uint32_t weight_addr) {
|
||||
#ifdef LACC_OP
|
||||
asm volatile (
|
||||
"lacc 0x2, $r0, %[addr], $r0, 0x5\n\t"
|
||||
::[addr]"r"(weight_addr)
|
||||
);
|
||||
#else
|
||||
asm volatile (
|
||||
"move $r5, %[addr]\n\t"
|
||||
".word 0xc08280a0\n\t"
|
||||
::[addr]"r"(weight_addr)
|
||||
: "$r5"
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define POOL_MODE_MIN 0
|
||||
#define POOL_MODE_MAX 1
|
||||
#define POOL_MODE_AVG 2
|
||||
|
||||
void inst_pool(int pool_mode) {
|
||||
#ifdef LACC_OP
|
||||
asm volatile (
|
||||
"lacc 0x2, $r0, %[pool_mode], $r0, 0x2\n\t"
|
||||
::[pool_mode]"r"(pool_mode)
|
||||
);
|
||||
#else
|
||||
asm volatile (
|
||||
"move $r5, %[pool_mode]\n\t"
|
||||
".word 0xc08100a0\n\t"
|
||||
::[pool_mode]"r"(pool_mode)
|
||||
:"$r5"
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
void inst_conf_offset(uint32_t buf_offset, uint32_t res_offset) {
|
||||
#ifdef LACC_OP
|
||||
asm volatile (
|
||||
"lacc 0x3, $r0, %[buf_offset], %[res_offset], 0x0\n\t"
|
||||
::[buf_offset]"r"(buf_offset), [res_offset]"r"(res_offset)
|
||||
);
|
||||
#else
|
||||
asm volatile (
|
||||
"move $r5, %[buf_offset]\n\t"
|
||||
"move $r6, %[res_offset]\n\t"
|
||||
".word 0xc0c018a0"
|
||||
::[buf_offset]"r"(buf_offset),[res_offset]"r"(res_offset)
|
||||
:"$r5", "$r6"
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
97
sdk/software/examples/lenet/ConvFuncs.c
Normal file
97
sdk/software/examples/lenet/ConvFuncs.c
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "ConvFuncs.h"
|
||||
|
||||
void conv_func(int8_t* d_i, int8_t* weight, int32_t* bias, int32_t* d_o, int8_t di_type,
|
||||
int height, int width, int padding, int channel, int out_channel,
|
||||
int kernel_width, int kernel_height) {
|
||||
// 使用多重循环卷积(BUF_HEIGHT - KERNEL_SIZE + PADDING * 2) / STRIDE + 1
|
||||
int16_t* d_16 = (int16_t*)d_i;
|
||||
int32_t* d_32 = (int32_t*)d_i;
|
||||
int height_o = (height - kernel_height + padding * 2) + 1;
|
||||
int width_o = (width - kernel_width + padding * 2) + 1;
|
||||
for (int c = 0; c < out_channel; c++) {
|
||||
for (int h = -padding; h < (height - kernel_height + padding) + 1; h++) {
|
||||
for (int w = -padding; w < (width - kernel_width + padding) + 1; w++) {
|
||||
int32_t sum = 0;
|
||||
for(int k = 0; k < channel; k++) {
|
||||
for (int m = 0; m < kernel_height; m++) {
|
||||
for (int n = 0; n < kernel_width; n++) {
|
||||
int h_m = h + m;
|
||||
int w_n = w + n;
|
||||
if (h_m >= 0 && h_m < height && w_n >= 0 && w_n < width) {
|
||||
if(di_type == 0){
|
||||
sum += d_i[(k * height + h_m) * width + w_n] *
|
||||
weight[((c * channel + k) * kernel_height + m) * kernel_width + n];
|
||||
} else if (di_type == 1) {
|
||||
sum += d_16[(k * height + h_m) * width + w_n] *
|
||||
weight[((c * channel + k) * kernel_height + m) * kernel_width + n];
|
||||
} else if (di_type == 2) {
|
||||
sum += d_32[(k * height + h_m) * width + w_n] *
|
||||
weight[((c * channel + k) * kernel_height + m) * kernel_width + n];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
d_o[c * height_o * width_o + (h+padding) * width_o + w + padding] = sum + bias[c];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pool_func(int32_t* d_i, int32_t* d_o, int channel, int height, int width) {
|
||||
for (int c = 0; c < channel; c++) {
|
||||
for (int h = 0; h < height / 2; h++) {
|
||||
for (int w = 0; w < width / 2; w++) {
|
||||
int32_t sum = d_i[(c * height + (h << 1)) * width + (w << 1)] +
|
||||
d_i[(c * height + (h << 1) + 1) * width + (w << 1)] +
|
||||
d_i[(c * height + (h << 1)) * width + (w << 1) + 1] +
|
||||
d_i[(c * height + (h << 1) + 1) * width + (w << 1) + 1];
|
||||
if(sum > 0) d_o[(c * height / 2 + h) * (width / 2) + w] = sum >> 2;
|
||||
else d_o[(c * height / 2 + h) * (width / 2) + w] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void linear_func(
|
||||
int32_t* d_i,
|
||||
int8_t* weight,
|
||||
int32_t* bias,
|
||||
int32_t* output,
|
||||
int input_size,
|
||||
int output_size) {
|
||||
|
||||
for (int i = 0; i < output_size; i++) {
|
||||
output[i] = bias[i];
|
||||
for (int j = 0; j < input_size; j++) {
|
||||
output[i] += d_i[j] * weight[i * input_size + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void relu_int(int32_t *x, int size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (x[i] < 0) {
|
||||
x[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void softmax(int32_t *x, float *output, int size) {
|
||||
int32_t max = x[0];
|
||||
for (int i = 1; i < size; i++) {
|
||||
if (x[i] > max) {
|
||||
max = x[i];
|
||||
}
|
||||
}
|
||||
|
||||
float sum = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
output[i] = exp((float)(x[i] - max)) ;
|
||||
sum += output[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
output[i] /= sum;
|
||||
}
|
||||
}
|
||||
16
sdk/software/examples/lenet/ConvFuncs.h
Normal file
16
sdk/software/examples/lenet/ConvFuncs.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef __CONV_FUNCS_H__
|
||||
#define __CONV_FUNCS_H__
|
||||
#include <stdint.h>
|
||||
|
||||
void conv_func(int8_t* d_i, int8_t* weight, int32_t* bias, int32_t* d_o, int8_t di_type,
|
||||
int height, int width, int padding, int channel, int out_channel,
|
||||
int kernel_width, int kernel_height);
|
||||
|
||||
void pool_func(int32_t* d_i, int32_t* d_o, int channel, int height, int width);
|
||||
|
||||
void linear_func(int32_t* d_i, int8_t* weight, int32_t* bias, int32_t* output, int input_size, int output_size);
|
||||
|
||||
void relu_int(int32_t *x, int size);
|
||||
|
||||
void softmax(int32_t *x, float *output, int size);
|
||||
#endif
|
||||
11
sdk/software/examples/lenet/Makefile
Normal file
11
sdk/software/examples/lenet/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
TARGET = lenet
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../bsp
|
||||
GCC_DIR=../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../toolchains/picolibc
|
||||
include ../../bsp/common.mk
|
||||
160
sdk/software/examples/lenet/main.c
Normal file
160
sdk/software/examples/lenet/main.c
Normal file
@@ -0,0 +1,160 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include "ConvFuncs.h"
|
||||
#include "weights.h"
|
||||
#include "test_image.h"
|
||||
#include "common_func.h"
|
||||
|
||||
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbf000000; //UART16550的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbf20f100; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 50000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
int start = 0;
|
||||
|
||||
|
||||
void InterruptInit(void)
|
||||
{
|
||||
// Enable button and timer Interrupt
|
||||
RegWrite(0xbf20f004,0x0f);//edge
|
||||
RegWrite(0xbf20f008,0x1f);//pol
|
||||
RegWrite(0xbf20f00c,0x1f);//clr
|
||||
RegWrite(0xbf20f000,0x1f);//en
|
||||
}
|
||||
|
||||
void HWI0_IntrHandler(void)
|
||||
{
|
||||
unsigned int int_state;
|
||||
int_state = RegRead(0xbf20f014);
|
||||
|
||||
if(int_state & 0xf){
|
||||
Button_IntrHandler(int_state & 0xf);
|
||||
}
|
||||
}
|
||||
|
||||
void Button_IntrHandler(unsigned char button_state)
|
||||
{
|
||||
if((button_state & 0b0001) == 0b0001){
|
||||
start = 1;
|
||||
RegWrite(0xbf20f00c,0x1);//clr
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int compare(int32_t* dut, int32_t* ref, int size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (dut[i] != ref[i]) {
|
||||
printf("Error at index %d: expected %d, got %d, %x\n", i, ref[i], dut[i], (uint32_t)&dut[i]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void printImage(int8_t* image, int height, int width) {
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
printf("%d ", image[i * width + j] != -1);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void flush_dcache(int size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
int index = size << 4;
|
||||
init_dcache_line(index);
|
||||
}
|
||||
}
|
||||
|
||||
int simu_flag;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
InterruptInit();
|
||||
simu_flag = RegRead(0xbf20f500);
|
||||
|
||||
int32_t conv1_out[6][28][28] = { 0 };
|
||||
int32_t pool1_out[6][14][14] = { 0 };
|
||||
int32_t conv2_out[16][12][12] = { 0 };
|
||||
int32_t pool2_out[16][6][6] = { 0 };
|
||||
int32_t fc1_out[10] = { 0 };
|
||||
int acc = 0;
|
||||
int begin_clk, end_clk;
|
||||
|
||||
int32_t accel_conv1_out[6][28][28];
|
||||
int32_t accel_pool1_out[6][14][14] = { 0 };
|
||||
int32_t accel_conv2_out[16][12][12] = { 0 };
|
||||
int32_t accel_pool2_out[16][6][6] = { 0 };
|
||||
int32_t accel_fc1_out[10] = { 0 };
|
||||
|
||||
int test_idx = 0;
|
||||
int test_num = 0;
|
||||
|
||||
printf("image num: %d\n", TEST_IMAGE_SIZE);
|
||||
|
||||
int clk, ret;
|
||||
while (1) {
|
||||
if(!simu_flag) delay_ms(200);
|
||||
if (start | simu_flag) {
|
||||
start = 0;
|
||||
printf("start\n");
|
||||
int gold_clk = 0;
|
||||
if (!simu_flag) {
|
||||
printImage(test_image[test_idx], 28, 28);
|
||||
|
||||
flush_dcache(256);
|
||||
|
||||
gold_clk = clock();
|
||||
conv_func(test_image[test_idx], w_conv1, b_conv1, conv1_out, 0, 28, 28, 1, 1, 6, 3, 3);
|
||||
relu_int(&conv1_out, 6 * 28 * 28);
|
||||
pool_func(conv1_out, pool1_out, 6, 28, 28);
|
||||
conv_func(pool1_out, w_conv2, b_conv2, conv2_out, 2, 14, 14, 0, 6, 16, 3, 3);
|
||||
relu_int(&conv2_out, 16 * 12 * 12);
|
||||
pool_func(conv2_out, pool2_out, 16, 12, 12);
|
||||
linear_func(pool2_out, w_fc1, b_fc1, fc1_out, 576, 10);
|
||||
gold_clk = clock() - gold_clk;
|
||||
|
||||
flush_dcache(256);
|
||||
|
||||
}
|
||||
|
||||
clk = clock();
|
||||
accel_conv_func(test_image[test_idx], w_conv1, b_conv1, accel_conv1_out, 0, 28, 28, 1, 1, 6, 3, 3, 1);
|
||||
accel_pool_func(accel_conv1_out, accel_pool1_out, 2, 6, 28, 28);
|
||||
accel_conv_func(accel_pool1_out, w_conv2_rev, b_conv2, accel_conv2_out, 2, 14, 14, 0, 6, 16, 3, 3, 1);
|
||||
accel_pool_func(accel_conv2_out, accel_pool2_out, 2, 16, 12, 12);
|
||||
accel_linear_func(accel_pool2_out, w_fc1, b_fc1, accel_fc1_out, 576, 10);
|
||||
clk = clock() - clk;
|
||||
|
||||
int index = 0;
|
||||
float max = accel_fc1_out[0];
|
||||
for (int j = 1; j < 10; j++) {
|
||||
if (accel_fc1_out[j] > max) {
|
||||
index = j;
|
||||
max = accel_fc1_out[j];
|
||||
}
|
||||
}
|
||||
printf("recognized number: %d\n", index);
|
||||
if (index == test_target[test_idx]) acc++;
|
||||
test_num++;
|
||||
test_idx = (test_idx + 1) % TEST_IMAGE_SIZE;
|
||||
if (simu_flag) {
|
||||
printf("Accuracy: %d/%d, clk: %d\n",
|
||||
acc, test_num, clk);
|
||||
} else {
|
||||
printf("Accuracy: %d/%d, gold_clk: %d, clk: %d speedup: %f\n",
|
||||
acc, test_num, gold_clk, clk, (float)gold_clk/(float)clk);
|
||||
}
|
||||
if (simu_flag) break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
23
sdk/software/examples/lenet/test_image.h
Normal file
23
sdk/software/examples/lenet/test_image.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef __TEST_IMAGE__H__
|
||||
#define __TEST_IMAGE__H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define TEST_IMAGE_SIZE 10
|
||||
|
||||
int8_t test_image[TEST_IMAGE_SIZE][28][28] = {
|
||||
{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 7, 0, -1, -1, -1, -1, 0, 7, 5, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 5, -1, -1, -1, -1, -1, 5, 8, 2, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 8, 8, 3, -1, -1, -1, -1, 0, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 8, 7, 0, -1, -1, -1, -1, 2, 8, 5, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 8, 7, -1, -1, -1, -1, 0, 8, 8, 2, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 5, 8, 4, -1, -1, -1, -1, 1, 8, 8, 0, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 5, 8, 7, 0, -1, -1, -1, 3, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 8, 4, -1, -1, -1, 4, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 6, 8, 8, 6, 6, 7, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 4, 7, 8, 8, 8, 8, 8, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 2, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 8, 8, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 7, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}},
|
||||
{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, 6, 8, 8, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 8, 8, 8, 8, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 5, 7, 6, 5, 3, 7, 8, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, -1, -1, 0, 5, 8, 6, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 2, 8, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 2, 7, 7, 8, 7, 7, 8, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 6, 8, 8, 6, 4, 5, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 5, 2, -1, -1, -1, 6, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 6, 0, -1, -1, -1, 0, 7, 8, 8, 8, 5, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 5, 8, 1, -1, -1, -1, -1, 4, 8, 4, 2, 8, 7, 0, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 1, -1, -1, -1, 2, 8, 8, 0, 0, 7, 8, 0, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 4, 8, 2, -1, -1, 0, 7, 8, 3, -1, -1, 4, 8, 6, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 0, 8, 7, 1, 1, 5, 8, 7, 0, -1, -1, 0, 3, 3, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 8, 8, 8, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 8, 8, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 7, 6, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}},
|
||||
{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 4, 8, 8, 3, 3, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 7, 8, 8, 8, 8, 8, 7, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 8, 7, 5, 2, 2, 5, 7, 7, 1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 6, 2, 0, -1, -1, -1, -1, 1, 7, 7, 1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 5, 6, 0, -1, -1, -1, -1, -1, -1, -1, 4, 8, 7, 0, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 0, 4, 1, 0, 0, -1, -1, -1, -1, -1, -1, 0, 4, 8, 4, 0, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 0, 0, 2, 7, 7, 1, -1, -1, -1, -1, -1, -1, 1, 8, 8, 0, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 4, 8, 8, 8, 2, -1, -1, -1, -1, -1, -1, 0, 7, 8, 0, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 5, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 4, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 0, 8, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 4, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 0, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 4, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 2, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 8, 2, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, 0, 7, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 6, 0, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, 0, 8, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, 8, 4, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 5, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, 3, 7, 8, 0, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 1, 8, 6, 0, -1, -1, -1, -1, -1, -1, 4, 7, 8, 4, 0, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 5, 8, 3, 0, -1, -1, -1, 0, 4, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 3, 8, 8, 5, 2, 2, 4, 5, 8, 8, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 8, 8, 8, 8, 8, 8, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 2, 5, 4, 3, 3, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}},
|
||||
{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 8, 5, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 6, 8, 5, 1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 6, 8, 5, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 6, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 6, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 5, 8, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 6, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 8, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 8, 6, 5, 4, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 5, 8, 6, 1, 2, 3, 6, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 8, 7, 1, -1, -1, -1, 0, 6, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 8, 1, -1, -1, -1, -1, -1, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 7, 8, 6, 0, -1, -1, -1, -1, 0, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 1, 8, 8, 1, -1, -1, -1, -1, 0, 7, 6, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 5, 8, 4, -1, -1, -1, -1, 0, 6, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 7, 8, 4, -1, -1, 0, 0, 7, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 5, 8, 8, 4, 3, 7, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 3, 7, 8, 8, 6, 3, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}},
|
||||
{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 0, 2, 2, 6, 8, 8, 8, 8, 8, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, 0, 1, 4, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, 5, 8, 8, 8, 8, 7, 6, 7, 6, 6, 6, 7, 8, 8, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, 1, 7, 8, 8, 2, 2, 0, -1, -1, -1, -1, -1, 2, 8, 8, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 5, 7, 8, 7, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 5, 8, 8, 7, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 8, 8, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 2, 6, 8, 8, 8, 8, 8, 8, 8, 7, 2, 1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 2, 0, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 8, 8, 7, 6, 6, 7, 6, 7, 8, 8, 8, 2, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 0, 2, 2, 2, 0, -1, -1, -1, -1, 0, 2, 8, 8, 7, 1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 8, 2, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 2, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 6, 0, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 7, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 5, 8, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 3, 7, 7, 8, 8, 7, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 5, 8, 8, 8, 8, 8, 5, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 5, 8, 8, 8, 8, 5, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}},
|
||||
{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 1, 4, 5, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 6, 8, 8, 8, 8, 8, 8, 0, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 8, 8, 8, 8, 4, 6, 8, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, 8, 7, 1, -1, -1, 5, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, 8, 4, -1, -1, 0, 7, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 7, -1, -1, 7, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 3, 3, 8, 8, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 7, 7, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 8, 8, 8, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 7, 8, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, 8, 8, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 8, 8, 7, 4, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 7, 2, -1, 3, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 8, 3, -1, -1, -1, 5, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 6, 0, -1, -1, -1, 4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 8, 2, -1, -1, -1, -1, 2, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 8, 0, -1, -1, -1, 2, 7, 8, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 4, 4, 5, 8, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 8, 8, 8, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 4, 8, 5, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}},
|
||||
{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 1, 3, 8, 8, 8, 8, 4, 0, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 0, 4, 5, 6, 8, 8, 8, 8, 8, 8, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 0, 8, 8, 8, 8, 8, 8, 8, 8, 6, 7, 8, 8, 8, 6, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 8, 8, 8, 8, 4, 0, 0, 1, 8, 8, 8, 6, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 3, 6, 1, -1, -1, -1, 6, 8, 8, 8, 6, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 8, 8, 8, 8, 3, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 7, 8, 8, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 7, 8, 8, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 5, 8, 8, 8, 8, 4, 0, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 8, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 8, 8, 5, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 8, 8, 8, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 8, 8, 8, 8, 8, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 0, 5, 8, 8, 8, 8, 8, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 5, 8, 8, 8, 8, 8, 8, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 8, 8, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 8, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 1, 7, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}},
|
||||
{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 2, 4, 7, 6, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 6, 8, 8, 8, 8, 8, 4, 1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 8, 5, 5, 7, 8, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 7, 8, 8, 6, 1, -1, -1, 0, 6, 8, 8, 7, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 7, 8, 8, 0, -1, -1, -1, 1, 8, 8, 8, 7, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 8, 8, 7, 3, 0, 0, 7, 8, 8, 8, 2, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 7, 8, 8, 8, 8, 8, 8, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 2, 6, 8, 8, 8, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 8, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 8, 8, 7, 7, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 8, 7, 0, 4, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 7, 8, 8, 3, -1, 4, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, -1, -1, 4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 5, 8, 8, 6, 0, 2, 7, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, 8, 8, 8, 8, 8, 8, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 8, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 7, 8, 8, 8, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 4, 8, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}},
|
||||
{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 4, 6, 8, 8, 8, 8, 1, 0, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 2, 5, 7, 8, 8, 8, 8, 8, 8, 8, 1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 7, 8, 8, 8, 8, 8, 8, 6, 7, 8, 8, 1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 8, 8, 8, 4, 4, 1, 0, 4, 8, 7, 0, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 4, 8, 8, 8, 8, 7, 1, -1, -1, -1, 5, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 6, 7, 6, 4, 0, -1, -1, 0, 5, 8, 8, 4, 0, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 2, 6, 6, 4, 6, 7, 8, 8, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 8, 8, 8, 8, 8, 7, 7, 8, 8, 8, 7, 0, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 5, 8, 8, 8, 6, 3, -1, 0, 4, 6, 8, 8, 1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 8, 0, 0, 0, -1, -1, -1, 0, 6, 8, 5, 0, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, -1, -1, -1, -1, -1, -1, 1, 6, 8, 4, 0, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 6, 8, 6, 0, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 8, 2, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, 0, 5, 8, 7, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 8, 7, 0, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, 0, 6, 8, 8, 8, 6, 1, -1, -1, -1, -1, -1, -1, 0, 7, 8, 8, 6, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, 1, 8, 8, 7, 8, 8, 8, 8, 3, 0, 0, 0, 4, 8, 8, 7, 0, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, 0, 6, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, 3, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, 0, 3, 8, 8, 8, 8, 4, 4, 4, 2, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}},
|
||||
{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 3, 3, 1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 2, 3, 3, 3, 7, 8, 8, 8, 8, 8, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 0, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 0, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 2, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 5, 1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 0, 6, 8, 8, 8, 8, 8, 6, 6, 6, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 6, 8, 8, 8, 8, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 8, 8, 8, 8, 7, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 8, 8, 8, 8, 8, 8, 7, 5, 5, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 5, 5, 5, 7, 8, 8, 8, 8, 6, 0, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 5, 8, 8, 8, 5, 0, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 4, 0, -1, -1, -1, 0, 7, 8, 8, 8, 0, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 3, 7, 8, 7, 3, 0, -1, -1, 1, 8, 8, 8, 2, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 3, 8, 8, 8, 8, 6, 2, 3, 7, 8, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 3, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 0, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 4, 8, 8, 8, 8, 8, 8, 4, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 3, 3, 3, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}
|
||||
};
|
||||
|
||||
int test_target[TEST_IMAGE_SIZE] = {4, 2, 0, 6, 3, 8, 7, 8, 3, 5};
|
||||
|
||||
#endif // __TEST_IMAGE__H__
|
||||
62
sdk/software/examples/lenet/weights.h
Normal file
62
sdk/software/examples/lenet/weights.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef __WEIGHTS__H__
|
||||
#define __WEIGHTS__H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int8_t w_conv1[6][3][3] = {
|
||||
{{-43, -52, -8}, {15, -8, 91}, {32, 101, 91}},
|
||||
{{-17, 33, -10}, {109, 106, 69}, {64, 89, 14}},
|
||||
{{0, -51, -93}, {-80, -43, -26}, {40, 78, 114}},
|
||||
{{75, 6, 83}, {34, 75, 65}, {-114, -120, -74}},
|
||||
{{60, 36, 44}, {34, 127, 9}, {75, 40, -49}},
|
||||
{{4, 7, 25}, {-91, -44, -109}, {-79, -28, -87}}
|
||||
};
|
||||
|
||||
int8_t w_conv2[16][6][3][3] = {
|
||||
{{{12, 13, -12}, {46, -29, -42}, {15, -25, -25}}, {{-8, 40, -29}, {27, 25, -42}, {15, 18, -23}}, {{-66, -41, -10}, {-58, -45, 6}, {-38, -50, -2}}, {{-9, -41, 1}, {-10, -72, -30}, {-26, -81, -65}}, {{27, 45, -23}, {13, 58, -45}, {23, 26, -57}}, {{-61, 15, 29}, {-39, 9, 44}, {0, 42, 13}}},
|
||||
{{{18, -67, -47}, {-49, -30, 46}, {-34, 33, 56}}, {{29, 14, -83}, {-79, -85, 9}, {-39, -14, 33}}, {{-2, -6, 58}, {23, 79, 108}, {8, 5, 3}}, {{58, 41, 45}, {45, -66, -13}, {-49, -2, 88}}, {{43, 41, -50}, {-37, -127, -40}, {-93, -16, 58}}, {{-20, -7, 31}, {22, 27, -32}, {15, -27, -46}}},
|
||||
{{{-69, -37, -1}, {13, -20, -71}, {64, 56, 34}}, {{-26, -19, 46}, {-15, -64, -87}, {50, 12, 42}}, {{-51, -52, -26}, {8, 18, -29}, {-18, -19, 14}}, {{20, 65, 75}, {-44, -11, 3}, {-7, 28, -84}}, {{-4, 7, 27}, {-23, -67, -47}, {55, 21, -27}}, {{38, 26, 28}, {28, -1, 28}, {-8, -30, 29}}},
|
||||
{{{-2, -1, 9}, {-32, -5, 15}, {30, -1, -20}}, {{-15, 21, -24}, {-18, 9, -19}, {18, -5, -46}}, {{-10, 16, 42}, {-11, -20, 5}, {-17, -13, 1}}, {{71, 49, -18}, {54, 63, 45}, {-81, -21, -14}}, {{9, 1, 10}, {21, 0, 34}, {-3, -40, -9}}, {{-45, 3, -20}, {13, 7, -1}, {30, 3, -2}}},
|
||||
{{{-42, -10, 0}, {-3, 26, -9}, {46, -26, -73}}, {{27, -44, 21}, {-19, 20, 10}, {-3, 20, -27}}, {{-17, 9, 5}, {55, 29, -61}, {43, -41, 9}}, {{49, 12, -34}, {-19, -28, 6}, {19, 21, -7}}, {{8, -28, 26}, {-46, 10, 41}, {29, 34, -30}}, {{-2, -14, -84}, {19, -46, -74}, {-33, -50, 18}}},
|
||||
{{{-22, -12, 50}, {-61, -3, 4}, {-35, -7, 6}}, {{48, -50, 9}, {11, -15, 18}, {-18, -22, 3}}, {{-41, -34, -26}, {0, -31, -69}, {25, 0, -40}}, {{11, -2, 7}, {-48, -92, -8}, {-74, -65, -38}}, {{20, -55, 54}, {13, -75, 50}, {-22, -14, 35}}, {{19, 13, -12}, {30, 29, -42}, {3, 32, -43}}},
|
||||
{{{9, 41, 25}, {-18, -26, -6}, {4, 7, 14}}, {{0, 32, 3}, {7, -1, 27}, {-10, -48, -4}}, {{1, -16, 4}, {-46, -24, -21}, {66, 51, 59}}, {{40, 53, -3}, {62, 72, 50}, {-50, -66, -35}}, {{-20, 19, 3}, {7, -3, 25}, {-47, -58, -15}}, {{-29, -31, -28}, {9, 10, 0}, {-3, 33, 13}}},
|
||||
{{{24, -14, -41}, {14, -12, 3}, {-2, 24, 27}}, {{20, -37, -70}, {-10, 19, -6}, {-27, 39, 32}}, {{-41, -30, 2}, {-31, 4, -23}, {16, -6, 19}}, {{-8, -68, -13}, {49, -14, -26}, {21, 94, 62}}, {{45, 7, -67}, {11, 21, -52}, {-18, -1, 10}}, {{-43, 21, 15}, {-75, -16, 8}, {12, -23, -53}}},
|
||||
{{{2, -9, 32}, {-23, 29, -9}, {-55, 26, -9}}, {{0, -43, 25}, {7, -33, 23}, {-55, 4, 27}}, {{1, 3, -61}, {17, -14, -120}, {-15, -63, -124}}, {{18, -46, -47}, {-2, -32, -58}, {-51, -28, -65}}, {{0, -49, 68}, {12, -14, 66}, {-36, -29, 62}}, {{21, 9, -19}, {48, 9, -70}, {32, -4, -57}}},
|
||||
{{{-38, 41, -14}, {38, 33, -58}, {23, -72, -33}}, {{-16, 20, -4}, {-36, 17, -30}, {2, -11, -49}}, {{11, 11, -35}, {54, 18, -21}, {33, -21, 9}}, {{-3, -34, -20}, {-32, -24, 27}, {3, 50, -8}}, {{-18, 33, 27}, {-27, 33, 18}, {38, 38, -37}}, {{15, -42, -52}, {-29, -55, -25}, {-60, -17, 45}}},
|
||||
{{{0, -33, -29}, {16, -7, -20}, {8, 22, -21}}, {{-6, -43, -36}, {2, -10, -7}, {8, 0, 9}}, {{52, 16, -14}, {-1, 30, 20}, {17, 16, 0}}, {{22, 60, 93}, {107, 51, -2}, {62, 41, 46}}, {{-24, -49, -29}, {-4, -23, -27}, {26, 18, 22}}, {{27, 9, 50}, {-37, -7, -9}, {-3, -23, -12}}},
|
||||
{{{-28, -79, -65}, {-18, 15, 36}, {-4, 55, 20}}, {{17, -12, -64}, {-32, -56, -15}, {-26, 26, 27}}, {{-45, 6, 27}, {40, 45, 46}, {56, 9, 48}}, {{93, 6, -28}, {14, -76, -29}, {-67, -12, 43}}, {{60, -33, -69}, {-48, -79, -12}, {-7, 7, 68}}, {{-6, -12, 9}, {-2, 14, -1}, {-24, -18, -5}}},
|
||||
{{{15, -4, -30}, {-3, 36, -29}, {-3, 23, 14}}, {{-5, 11, -30}, {-5, 36, -3}, {-30, 36, 29}}, {{-22, -35, -23}, {-38, -41, 1}, {-27, -63, 23}}, {{0, -50, -83}, {-25, -75, -111}, {-50, -26, -29}}, {{-37, 20, 4}, {1, 38, -8}, {9, 49, 27}}, {{-48, -80, -20}, {6, -33, -30}, {1, -51, -39}}},
|
||||
{{{15, -22, -26}, {21, -1, 11}, {-23, 6, -13}}, {{-10, -41, -15}, {25, -5, -4}, {-31, -26, -19}}, {{-17, 7, 10}, {0, -21, -8}, {-5, 10, 47}}, {{5, -55, -38}, {55, 62, 45}, {54, 55, 14}}, {{-17, -28, -12}, {31, 35, 30}, {-17, -6, 2}}, {{2, -20, -6}, {-10, -22, 12}, {27, 14, 25}}},
|
||||
{{{-8, -27, 36}, {-31, 37, 50}, {-57, 28, 12}}, {{24, -67, -46}, {-18, -24, 30}, {-41, 1, -4}}, {{12, 18, 92}, {-27, 12, 33}, {7, -11, -27}}, {{29, -33, -123}, {-61, -85, 4}, {-44, -75, -35}}, {{21, -68, -77}, {1, -60, 14}, {-77, -22, 52}}, {{5, 0, 31}, {7, 20, -13}, {-2, 5, 5}}},
|
||||
{{{-28, -15, -5}, {16, 16, 14}, {-25, -8, -37}}, {{-18, -30, -30}, {28, 23, 30}, {-14, 16, 8}}, {{0, 3, 6}, {-7, 4, -5}, {-27, -44, -41}}, {{5, 23, 16}, {11, -5, 9}, {50, 71, 40}}, {{-7, -22, -36}, {37, 0, 20}, {27, 39, 10}}, {{10, 30, 3}, {-24, -17, -16}, {2, -29, 3}}}
|
||||
};
|
||||
|
||||
int8_t w_conv2_rev[6][16][3][3] = {
|
||||
{{{12, 13, -12}, {46, -29, -42}, {15, -25, -25}}, {{18, -67, -47}, {-49, -30, 46}, {-34, 33, 56}}, {{-69, -37, -1}, {13, -20, -71}, {64, 56, 34}}, {{-2, -1, 9}, {-32, -5, 15}, {30, -1, -20}}, {{-42, -10, 0}, {-3, 26, -9}, {46, -26, -73}}, {{-22, -12, 50}, {-61, -3, 4}, {-35, -7, 6}}, {{9, 41, 25}, {-18, -26, -6}, {4, 7, 14}}, {{24, -14, -41}, {14, -12, 3}, {-2, 24, 27}}, {{2, -9, 32}, {-23, 29, -9}, {-55, 26, -9}}, {{-38, 41, -14}, {38, 33, -58}, {23, -72, -33}}, {{0, -33, -29}, {16, -7, -20}, {8, 22, -21}}, {{-28, -79, -65}, {-18, 15, 36}, {-4, 55, 20}}, {{15, -4, -30}, {-3, 36, -29}, {-3, 23, 14}}, {{15, -22, -26}, {21, -1, 11}, {-23, 6, -13}}, {{-8, -27, 36}, {-31, 37, 50}, {-57, 28, 12}}, {{-28, -15, -5}, {16, 16, 14}, {-25, -8, -37}}},
|
||||
{{{-8, 40, -29}, {27, 25, -42}, {15, 18, -23}}, {{29, 14, -83}, {-79, -85, 9}, {-39, -14, 33}}, {{-26, -19, 46}, {-15, -64, -87}, {50, 12, 42}}, {{-15, 21, -24}, {-18, 9, -19}, {18, -5, -46}}, {{27, -44, 21}, {-19, 20, 10}, {-3, 20, -27}}, {{48, -50, 9}, {11, -15, 18}, {-18, -22, 3}}, {{0, 32, 3}, {7, -1, 27}, {-10, -48, -4}}, {{20, -37, -70}, {-10, 19, -6}, {-27, 39, 32}}, {{0, -43, 25}, {7, -33, 23}, {-55, 4, 27}}, {{-16, 20, -4}, {-36, 17, -30}, {2, -11, -49}}, {{-6, -43, -36}, {2, -10, -7}, {8, 0, 9}}, {{17, -12, -64}, {-32, -56, -15}, {-26, 26, 27}}, {{-5, 11, -30}, {-5, 36, -3}, {-30, 36, 29}}, {{-10, -41, -15}, {25, -5, -4}, {-31, -26, -19}}, {{24, -67, -46}, {-18, -24, 30}, {-41, 1, -4}}, {{-18, -30, -30}, {28, 23, 30}, {-14, 16, 8}}},
|
||||
{{{-66, -41, -10}, {-58, -45, 6}, {-38, -50, -2}}, {{-2, -6, 58}, {23, 79, 108}, {8, 5, 3}}, {{-51, -52, -26}, {8, 18, -29}, {-18, -19, 14}}, {{-10, 16, 42}, {-11, -20, 5}, {-17, -13, 1}}, {{-17, 9, 5}, {55, 29, -61}, {43, -41, 9}}, {{-41, -34, -26}, {0, -31, -69}, {25, 0, -40}}, {{1, -16, 4}, {-46, -24, -21}, {66, 51, 59}}, {{-41, -30, 2}, {-31, 4, -23}, {16, -6, 19}}, {{1, 3, -61}, {17, -14, -120}, {-15, -63, -124}}, {{11, 11, -35}, {54, 18, -21}, {33, -21, 9}}, {{52, 16, -14}, {-1, 30, 20}, {17, 16, 0}}, {{-45, 6, 27}, {40, 45, 46}, {56, 9, 48}}, {{-22, -35, -23}, {-38, -41, 1}, {-27, -63, 23}}, {{-17, 7, 10}, {0, -21, -8}, {-5, 10, 47}}, {{12, 18, 92}, {-27, 12, 33}, {7, -11, -27}}, {{0, 3, 6}, {-7, 4, -5}, {-27, -44, -41}}},
|
||||
{{{-9, -41, 1}, {-10, -72, -30}, {-26, -81, -65}}, {{58, 41, 45}, {45, -66, -13}, {-49, -2, 88}}, {{20, 65, 75}, {-44, -11, 3}, {-7, 28, -84}}, {{71, 49, -18}, {54, 63, 45}, {-81, -21, -14}}, {{49, 12, -34}, {-19, -28, 6}, {19, 21, -7}}, {{11, -2, 7}, {-48, -92, -8}, {-74, -65, -38}}, {{40, 53, -3}, {62, 72, 50}, {-50, -66, -35}}, {{-8, -68, -13}, {49, -14, -26}, {21, 94, 62}}, {{18, -46, -47}, {-2, -32, -58}, {-51, -28, -65}}, {{-3, -34, -20}, {-32, -24, 27}, {3, 50, -8}}, {{22, 60, 93}, {107, 51, -2}, {62, 41, 46}}, {{93, 6, -28}, {14, -76, -29}, {-67, -12, 43}}, {{0, -50, -83}, {-25, -75, -111}, {-50, -26, -29}}, {{5, -55, -38}, {55, 62, 45}, {54, 55, 14}}, {{29, -33, -123}, {-61, -85, 4}, {-44, -75, -35}}, {{5, 23, 16}, {11, -5, 9}, {50, 71, 40}}},
|
||||
{{{27, 45, -23}, {13, 58, -45}, {23, 26, -57}}, {{43, 41, -50}, {-37, -127, -40}, {-93, -16, 58}}, {{-4, 7, 27}, {-23, -67, -47}, {55, 21, -27}}, {{9, 1, 10}, {21, 0, 34}, {-3, -40, -9}}, {{8, -28, 26}, {-46, 10, 41}, {29, 34, -30}}, {{20, -55, 54}, {13, -75, 50}, {-22, -14, 35}}, {{-20, 19, 3}, {7, -3, 25}, {-47, -58, -15}}, {{45, 7, -67}, {11, 21, -52}, {-18, -1, 10}}, {{0, -49, 68}, {12, -14, 66}, {-36, -29, 62}}, {{-18, 33, 27}, {-27, 33, 18}, {38, 38, -37}}, {{-24, -49, -29}, {-4, -23, -27}, {26, 18, 22}}, {{60, -33, -69}, {-48, -79, -12}, {-7, 7, 68}}, {{-37, 20, 4}, {1, 38, -8}, {9, 49, 27}}, {{-17, -28, -12}, {31, 35, 30}, {-17, -6, 2}}, {{21, -68, -77}, {1, -60, 14}, {-77, -22, 52}}, {{-7, -22, -36}, {37, 0, 20}, {27, 39, 10}}},
|
||||
{{{-61, 15, 29}, {-39, 9, 44}, {0, 42, 13}}, {{-20, -7, 31}, {22, 27, -32}, {15, -27, -46}}, {{38, 26, 28}, {28, -1, 28}, {-8, -30, 29}}, {{-45, 3, -20}, {13, 7, -1}, {30, 3, -2}}, {{-2, -14, -84}, {19, -46, -74}, {-33, -50, 18}}, {{19, 13, -12}, {30, 29, -42}, {3, 32, -43}}, {{-29, -31, -28}, {9, 10, 0}, {-3, 33, 13}}, {{-43, 21, 15}, {-75, -16, 8}, {12, -23, -53}}, {{21, 9, -19}, {48, 9, -70}, {32, -4, -57}}, {{15, -42, -52}, {-29, -55, -25}, {-60, -17, 45}}, {{27, 9, 50}, {-37, -7, -9}, {-3, -23, -12}}, {{-6, -12, 9}, {-2, 14, -1}, {-24, -18, -5}}, {{-48, -80, -20}, {6, -33, -30}, {1, -51, -39}}, {{2, -20, -6}, {-10, -22, 12}, {27, 14, 25}}, {{5, 0, 31}, {7, 20, -13}, {-2, 5, 5}}, {{10, 30, 3}, {-24, -17, -16}, {2, -29, 3}}}
|
||||
};
|
||||
|
||||
int8_t w_fc1[10][576] = {
|
||||
{-6, -4, -15, -14, -18, 2, -7, -15, 0, -10, -5, -2, -6, 21, 14, -15, 11, 11, -1, 13, 21, -61, -12, -4, 3, 21, -18, -26, -15, -12, 4, 0, -13, -25, -30, -27, -12, -10, -15, -15, -7, -4, 0, -6, -8, -13, -34, -3, -7, 5, -8, -31, -6, -15, -24, -3, -4, -12, 4, 0, -23, -51, -28, -3, 20, 6, -13, -28, -17, 0, 5, 1, 4, 4, -8, 0, -7, -6, -3, -18, -10, -2, -1, -12, -9, -28, -21, -32, -39, -16, -24, -58, -24, -10, -30, -22, -14, -13, -25, 0, -5, 1, -10, -1, 5, 4, 5, 1, -1, -10, -10, -5, 4, -1, -4, -16, 2, 11, -8, -10, -5, -11, -28, -5, -18, -24, -3, -23, -73, -69, -2, 9, -18, -13, -23, -16, 0, -1, 5, -8, 11, -6, -18, -10, 4, -15, -16, -18, -21, 2, -4, -1, -12, -25, -37, -26, -6, 10, 0, -51, -2, 1, 14, 7, -34, 4, 12, 14, 5, -9, -14, 3, 5, 1, 7, 2, -18, -45, -16, -1, -4, -5, -9, -2, -7, -5, -11, -11, -19, -3, -3, -2, -5, -1, -20, 7, 39, 0, 1, 17, -29, 24, 41, -4, -10, 15, -35, -20, -6, -14, -16, -4, -28, -61, -26, -8, 4, -11, -21, -16, -13, -1, -2, -24, -24, 8, -5, -22, -11, -22, -24, -7, -5, -35, -8, -16, -43, -57, -3, 0, -21, -9, -9, -7, -6, -5, 7, -8, 7, -12, -18, -10, -2, -11, -12, -9, -8, -3, -5, -12, -11, 20, -6, 7, -6, -21, -13, -13, -1, 1, -10, 8, 16, -32, -10, 2, -8, 8, 11, -24, -20, -16, -6, 11, 14, -19, -26, -20, -6, -14, -8, -4, 4, -7, 0, -6, -13, -12, 4, -5, 8, -9, 3, -2, 14, 7, 18, 20, -13, 6, 23, 6, 5, -3, -23, -26, -10, -4, 10, -13, -24, -43, -19, -6, 6, -15, -12, -11, -30, -2, -6, -4, 4, -15, -44, -15, -11, 8, 5, -41, -6, 16, 7, 10, -2, -3, 10, 14, 4, -18, 4, 0, 1, 1, 5, -10, -16, -21, -12, -7, -8, -16, -5, -1, -9, -3, -4, -3, -8, 8, -3, -13, 2, 3, -18, -74, -25, -3, -10, -39, -31, -12, -23, -26, -24, -14, -8, 1, -19, -28, -12, -18, 3, 11, -5, 4, -9, -7, -16, -15, -20, -5, -6, -8, -8, -16, -56, -17, -1, 3, -3, -51, -37, -27, -11, -24, -22, 9, -2, -6, -18, -47, -14, 12, 36, 0, -3, -11, 3, 12, -3, -6, -8, -8, 12, -5, 3, 4, -6, 1, -9, 4, -5, 16, -8, -9, -4, -18, 8, 20, -3, -13, -1, -29, -18, 14, 3, -3, 13, -15, -23, -9, -5, -6, -20, -22, -10, -8, -8, -13, -28, -12, -22, -19, -11, -14, -3, -1, -14, -25, -1, -17, -23, -44, -5, 4, -2, 7, -55, -39, 8, -9, 2, -5, 0, -3, -8, -17, 2, 2, 20, 12, -18, -21, -16, -2, -12, -6, -5, -7, -2, 2, 7, -12, -36, -4, 7, -4, -9, -27, -10, -16, -5, -4, -7, 14, -1, -10, -16, -57, -30, -4, 14, 2, -8, -40, -26, 8, 9, 3, -6, -16, -2, -12, -8, -4, -7, -7, -5, 6, -4, 0, -3, -2, -17, -80, -21, -7, -12, -22, -31, -35, -25, -20, -17, -21, 3, 5, -13, -19, -14, -23, -6, 12, -7, -10},
|
||||
{7, 12, 25, 18, 2, -6, -5, -13, 6, 35, -3, -6, 9, -11, -14, 15, -10, -20, 4, -3, -6, 10, -32, -6, 5, 8, 35, -24, -28, 0, -5, 5, -9, -9, -8, 2, -18, -16, -5, 2, 7, 5, -9, -30, -25, 30, 1, 2, -3, -16, 9, 5, -8, -4, -20, -23, -1, -11, -7, 8, 7, 3, 18, -7, -23, -7, -6, -18, -35, -23, -13, -7, -4, -2, -14, -13, -10, -11, -8, 6, -9, 14, -11, -12, -10, 3, -33, -12, -27, -18, -5, 3, -40, -15, 13, -4, -5, 6, 21, 16, 3, -12, -9, -11, 4, 7, 1, -5, -1, -9, -13, -4, 2, 7, -5, -27, -26, -40, -44, -16, -7, -10, 0, -24, -39, -16, 5, -22, -10, -40, -26, -3, -10, -16, -17, -5, -22, 3, 0, -4, -21, -9, 1, 1, -7, -14, 7, -5, -2, -14, -11, -28, 0, -5, -7, -16, -13, -15, 0, -13, -30, 2, -14, -25, -16, -34, -13, 4, -19, 6, -8, -49, -26, -5, -5, -5, -19, -13, -5, -2, -6, -11, 3, 0, 11, -5, -7, -20, 0, 35, 27, 2, -8, -19, -3, 23, 14, 6, -17, -28, 25, -11, 10, 7, -7, -14, 31, -13, 4, -2, -4, -10, -12, 4, -12, 0, -1, -7, -22, -21, -5, -8, -4, -14, -20, -66, -59, -15, -11, -9, 13, -17, -39, -12, 4, -22, -5, -33, -26, -4, -22, -21, -26, -6, -4, 4, -7, 8, -26, 2, 5, 3, 3, -1, -29, -24, -19, -1, -3, 5, 4, -15, -3, -8, 4, -9, -49, 26, 2, -21, -3, -11, -55, -6, -23, -5, 1, 5, 1, 1, -5, -5, 7, 4, 26, -6, -6, -2, -6, -2, 22, 13, 16, 1, -17, -9, 9, 36, 13, -7, -13, -19, 1, 19, -8, 0, -24, -12, 12, -9, -16, 5, -16, -13, 16, -6, -8, 7, -9, -11, -14, 2, -4, -5, 1, -15, -2, 0, -6, -5, -8, -27, -14, -13, 5, -23, 1, -7, -11, -3, -21, -7, 1, -6, -15, -4, -29, -12, -3, 5, -21, -25, -21, -10, -2, -17, -23, -9, -5, 4, 7, -19, -17, -27, -13, -11, -3, -11, -35, -20, -57, -30, 0, -3, -30, -16, -58, -5, -9, -18, -27, -32, -36, 4, 14, 15, 1, 2, 12, 8, -1, -14, -24, -6, -13, 8, -6, -13, -13, -1, 2, -13, -1, -15, -35, 7, -10, -3, -1, -3, 2, -2, -23, -2, -18, -8, -10, -8, -1, 10, 14, 10, 9, -27, -45, -9, -9, -4, -13, -39, -21, -4, 5, -12, -8, 4, -6, -4, -10, -19, 14, 16, 9, -6, -3, -21, -32, 5, -5, -10, -7, -13, -11, 12, -26, -12, -4, -14, -6, 12, 2, -2, 0, 1, -12, -23, 1, -8, -1, -19, -33, -40, -27, -4, -3, -13, -9, -32, -46, -12, -2, -15, -16, -31, -55, -15, 1, -25, -28, -42, -87, -7, -9, 7, 0, -19, 5, -6, 7, -10, -32, -12, 3, -7, -9, -12, 5, 19, 24, -10, -15, -24, -7, 39, 50, 6, -9, -8, 19, 18, 30, 4, -9, -5, 1, -8, 13, -16, 3, -3, -19, 15, -8, -20, -6, 0, 3, -12, -25, -19, 5, -16, -19, -19, -22, -20, -9, -17, -24, -7, -28, -25, -2, -10, -42, -14, -55, -2, -12, -13, -42, -37, -50, -5, 1, 13, -22, 18, 17, 12, 4, -29, -42, -36, -16, -5},
|
||||
{-6, -5, -8, -6, 2, 6, -2, -16, -9, 5, -5, 6, -5, -50, -33, -5, -2, -8, -5, -63, -35, -10, -15, -34, 5, 6, -11, -30, -15, -28, 9, 4, -43, -33, -4, -21, -11, -21, -32, -31, -33, -6, -3, 6, -25, -45, -23, -6, 14, 13, -11, -8, 8, 30, 12, 26, 19, 8, 22, -3, -18, -9, 8, -15, -32, 5, -28, -37, -17, -28, -13, -13, -11, -8, -9, -2, -11, -9, 4, 15, -1, -16, 7, -11, 6, 34, 39, 19, -30, -7, 2, -20, -42, -43, -17, -8, -19, -59, -26, 3, 43, 17, -8, -13, -2, 21, 12, -9, -2, 25, 29, 5, -7, -14, -11, -2, 17, -3, -31, -42, 6, 0, -19, -17, -42, -18, -25, -35, -30, -26, -11, 32, -1, -16, -3, 3, 18, 28, 14, -2, -7, 11, 11, 8, 5, 3, -3, -12, -28, -2, 0, -3, -7, -33, -36, -30, -17, -26, -33, -7, 15, 18, -1, 4, 14, 7, 5, 14, 13, 8, -3, -13, -54, 3, 6, -22, -46, -53, -25, -6, -2, 8, -15, -27, -29, 12, -12, -17, -19, 8, 7, 8, -29, -36, -32, 23, 20, 11, -8, -21, -11, -7, -41, -10, 0, 11, -13, -49, -28, -23, -7, -20, -56, -12, 12, -8, -8, 17, 16, 21, -15, -14, -10, 4, 3, 18, -11, -40, 0, 11, -5, 1, -31, -24, -21, -55, -36, -29, -27, 33, -10, -26, -14, 5, 25, 26, 3, -2, -5, 4, 4, -1, 5, -7, 16, 14, 11, -14, 8, -23, 5, 13, -2, -8, 13, -33, -24, -14, -7, 3, 3, -74, -53, -8, -22, -12, -5, -43, -26, 24, 0, -18, -4, -8, -49, -15, 18, -14, -14, -11, -23, -19, -24, -8, -7, -19, -26, -14, 13, -7, -45, -48, -45, 1, 16, 2, -15, -13, -18, 15, -26, 0, 16, 19, -10, -38, -39, -6, -2, -20, -44, -46, -10, 1, -3, 7, -13, -24, -26, -5, 1, 8, 5, -21, -37, -19, 0, -23, -50, -19, 14, 8, 1, -11, 12, 11, 7, -4, 16, 9, -7, -10, -33, -19, 9, -25, -23, -44, -33, -5, -13, -5, -7, 3, -5, -24, -4, -17, -20, -12, -31, -28, 13, 30, 21, -12, -32, -1, 18, 8, -8, -1, -16, 7, -19, -36, -23, 4, 54, 49, -35, -36, -28, 10, 35, 2, -9, -10, -26, -22, -32, -15, 0, 10, -16, -69, -68, -13, 19, 26, 3, -9, -5, 24, 10, 22, 3, 25, 30, 5, -18, -11, 0, 4, -21, -9, -26, -10, -7, -33, -19, -18, 3, 1, 10, -4, 1, -4, 1, -28, 7, 1, 4, -21, -16, -51, -28, -28, 8, -17, 5, -39, 10, -15, 3, -19, 12, 1, 26, -7, -12, -10, -1, -6, -27, -22, -12, -1, 0, 16, 19, 4, -3, -27, -8, -7, -9, -10, -39, -33, -10, -10, -27, -47, -45, -8, -9, -9, 6, 6, 4, 31, 17, -19, -17, -15, 20, 18, -11, -14, -10, -8, 6, 1, -7, -9, -16, -29, -15, -1, -4, 1, -20, -53, -18, 13, 5, -15, -13, -5, 15, 6, 8, 25, 28, 0, 38, -19, -10, 5, 17, -21, -76, -27, -28, -34, 10, -20, -37, -8, -4, 6, -1, -8, -5, -11, 8, -4, -2, -13, -33, -31, 15, 11, 13, -32, -43, -10, 18, 7, -4, -8, 5, 17, -12, -25, -2, 7, 30, 24, -25, -50, -15, -2, 16, 10},
|
||||
{2, -9, 4, 6, 7, -7, -2, -36, -29, 12, 7, 13, 5, -31, -39, -36, 8, -20, 0, -35, -45, -27, 4, -13, 5, -59, -86, -1, 14, 6, -1, -22, -27, 1, 5, -16, 3, -3, -12, -34, -47, -3, -4, -11, -8, -55, -39, -16, -13, 28, 58, -3, -28, -5, -19, -32, -31, -26, -18, -5, -16, -20, 3, 10, 5, -11, 5, 22, 35, 40, -9, -8, -9, -3, 6, 7, -4, -4, -1, 8, 6, -10, -23, -21, 2, -16, -32, -37, -7, -6, 5, 19, 38, 3, -11, -13, -3, 19, 23, -13, -46, -16, -9, -13, -25, -35, -43, -6, 5, 24, 37, 12, -10, 0, 16, 2, -14, -19, -54, -44, 5, -5, -6, 0, -10, -4, -34, -25, -10, 10, 2, -44, 15, -9, -8, -22, -30, -36, -1, 10, 1, -3, -11, -24, 4, -9, -30, -17, -9, -18, 8, -6, -3, 3, 8, -19, -17, -31, 23, 31, -10, -12, -39, -53, -15, -29, -23, -20, -9, -48, -19, 6, 15, -5, -17, -8, 0, 16, -4, 6, 4, -10, -25, -39, -24, 2, -11, -33, -48, -53, -5, 18, -30, -22, -12, -44, -56, 3, -37, -19, 3, -50, -23, 4, -9, -44, -50, -18, -4, 4, -1, -13, -52, -26, -22, 10, 10, 16, 32, 14, -4, -7, 4, 15, 17, -11, -59, -48, -7, 6, 13, -13, -11, -23, -28, -9, 0, 4, -19, -47, 10, -9, 15, -11, -34, -42, -8, -7, -12, -6, -13, -17, 0, 6, 14, -4, 10, 2, 4, -6, 0, 8, 5, 1, 0, -73, -93, 2, 7, 4, 9, -26, -45, -7, 4, -9, 21, -10, -35, -8, 7, 4, 9, 4, -42, -22, -18, -16, -2, -27, -28, -10, -16, -7, -26, -50, -44, -49, -6, -4, -57, -31, -5, -39, -47, -6, -35, -31, -18, -64, -26, 1, -25, -35, -67, -36, -14, -3, -20, -20, -25, -14, -10, -6, 6, 11, -39, -44, -17, -7, 16, -16, -18, 13, 26, -8, -8, -32, -13, 11, 1, -16, -25, -70, -36, -28, -17, -14, -3, -46, -48, 11, 10, -6, -8, 4, 6, 6, 7, 0, 3, 2, -3, 8, 8, -19, -3, -5, 4, -1, -21, -37, -3, -17, -26, -1, -12, -35, -4, -1, -7, -10, 3, 1, 6, 21, 11, 2, -24, -38, 17, 40, 38, 3, -26, -16, -2, -12, -2, -12, -27, -17, -7, -5, -9, -53, -44, -18, -12, -1, 38, 14, 2, 6, -21, -35, -15, -27, -24, -2, -11, -13, -13, -7, -3, -13, 12, 28, 38, 20, -1, 3, 1, 3, 2, 14, 13, 0, 9, -23, 6, 5, 10, 3, -9, -66, -13, -14, -16, -29, 13, -9, -8, -16, -5, -1, 9, -8, -23, -12, -2, 4, 11, 1, -23, -15, 4, -6, 9, 11, 22, -5, -18, -24, 20, 16, 7, 8, -22, -26, -8, -20, -2, 25, 19, -14, -15, -26, -15, 4, -10, -41, 1, -6, -26, 6, -21, -32, 8, 17, 10, -12, -17, -21, -4, -10, -27, -40, -30, -6, -9, -27, -78, -87, -12, -9, -15, -6, 27, -27, -40, -8, -21, -31, -17, -36, -39, 0, -19, -18, 7, -12, -21, -1, 4, 1, 24, 7, 7, 2, -2, 2, -11, 4, 3, -17, 1, 10, 11, 11, -7, -16, -9, 0, -12, 5, -7, -44, -11, -17, 4, -2, -4, 3, 4, 14, 18, -4, -23, -26, 11, 31, 29, -3, -21, -7},
|
||||
{-5, 1, -7, 1, -28, -15, -3, 30, 44, 9, -4, -13, -3, 11, 3, -20, 0, -23, -2, 1, -21, -9, -5, -20, 5, -5, -2, 5, -7, -17, 0, 0, 0, -12, -16, -2, 1, 3, 1, 3, 19, 15, -11, -2, -9, -4, 28, 0, -6, 0, -68, -18, -8, -19, -18, -18, -40, -15, 1, -1, -12, 5, -11, -25, -12, -2, -17, -23, -25, -37, -19, -3, -7, 5, -12, -13, -13, -9, -16, -15, -44, -77, -34, -9, -6, -51, -33, -39, -11, 8, -1, 7, 22, -14, -11, 6, -6, -11, -8, -36, 2, -8, 1, -22, -41, -31, -19, -10, 3, -14, -19, -15, -7, 2, -1, -22, -77, -76, -65, 9, -7, -15, -24, -24, -60, -11, 1, 5, 28, 27, 11, -15, -16, -9, -9, 18, 10, -10, -11, -26, -38, -23, 4, 1, 0, -13, -18, -15, -17, 14, -11, -15, -4, 7, 24, 6, -13, 30, -6, 7, 3, -7, 8, 0, -47, 10, -26, -9, -8, -17, -8, -10, -32, -1, -8, -1, -1, 11, 0, -3, -7, -8, 6, 5, 17, -4, -2, 1, 31, 58, 56, 1, 6, 16, -25, 6, 23, -7, -5, -7, -27, -5, -27, -8, -22, -29, 16, 11, -9, -3, -9, -11, 4, 9, 6, -4, -6, -10, -15, -20, -14, -7, -1, -4, -79, -94, -76, 3, -18, -26, -35, -20, -45, -12, 1, -5, 20, 14, 11, -12, -14, -3, -19, 8, -9, -19, -20, -20, -21, -2, 4, 9, -3, -24, -66, -64, -34, -8, -10, -1, -8, -11, -26, -22, 0, 11, 36, -26, 8, -38, -3, 16, 32, -27, 12, -10, -7, -31, -34, -27, -17, -14, 5, -15, 3, 7, -4, -5, -1, -15, 16, 25, 22, 1, -7, 1, 29, 68, 51, 9, -5, -2, -11, 23, 25, 4, 4, -13, -24, 22, 5, 4, -19, -14, 3, 16, 6, -5, -16, -2, -17, -6, 9, -7, -6, -11, -17, -16, -4, 6, -4, -12, -4, 12, 16, 4, -20, 23, 8, -6, -4, -10, 17, 8, -12, 4, -15, -8, -18, -7, -7, -8, -28, -5, -2, -12, -22, -6, -1, -8, 2, -1, -25, -19, -24, 8, -15, -10, -9, -36, -20, -24, -8, -7, -2, -20, 5, -8, -12, -21, 3, 6, -1, -2, -1, -8, -30, -59, -13, -8, 4, -30, -52, -21, -15, -1, -3, -6, -5, -9, 4, 9, -7, -12, -23, 1, 27, 0, -8, -4, -35, -8, -9, -11, -5, -19, -26, -10, 10, 1, -11, 11, -40, -30, -20, -7, -11, -14, -28, -35, -17, -5, -2, -24, -43, -29, -29, 8, -3, 10, 1, -4, -35, -18, 5, 22, 11, 9, -4, -15, -1, 14, -15, -6, -1, -9, -5, -37, -58, -8, -8, -12, -2, -8, -8, -22, -13, 7, -2, -11, -26, -52, -30, -1, -4, -29, -58, -68, -53, -9, -16, -11, -6, -15, 5, -16, 11, 22, 25, 40, 19, 0, -11, -25, -18, -20, -21, -4, -11, -16, -25, -38, -3, 5, -13, -6, 3, 9, 5, -2, -10, -3, 1, 37, 26, -1, 8, 9, -54, -10, -5, -19, -11, -16, -57, -25, -25, -16, 3, 14, -15, -23, -13, -13, -8, -2, -13, -50, -25, -9, 2, 2, -19, -32, -30, 4, -14, -21, -21, -32, -21, -27, -7, 10, 9, -16, 2, -12, -4, -5, 4, 10, 10, -9, -8, -15, -34, -48, -15, -9, 6, -23, -57, -51, -25, -2},
|
||||
{5, -4, -37, -55, -7, -30, -6, -2, 10, -53, -29, -53, 6, -23, 7, -28, -29, -49, -5, -50, -15, -22, -9, -21, -5, -33, -25, -6, -1, 0, 1, -19, -9, 2, -14, 5, -23, -6, -4, -3, 6, 4, -12, -24, -16, 8, 43, 24, -28, -42, -29, -49, -34, -8, -8, -35, -27, -23, -40, -8, 0, 14, 3, 4, -7, -8, -7, -5, 16, 14, 13, -9, -7, -5, 0, -8, -19, -17, -14, -38, -10, 14, -2, -2, -12, -5, 18, 57, 36, 21, 17, 29, 2, 10, 8, -2, -10, 10, 11, -4, -14, -19, -3, -1, -12, -24, -12, -6, -13, -16, -22, 7, 14, 1, -22, -33, 0, 22, 37, 33, -17, -7, -5, 8, 17, 20, -4, 16, 2, -18, -40, -30, -1, 4, -4, -43, -28, -20, -25, -4, 5, -5, -5, 0, -6, -2, -8, 8, 21, 19, -10, -19, -17, -27, -6, 52, -12, -7, -12, -102, -127, -23, -16, -27, -39, -37, -34, -19, 5, -16, -11, 0, 3, 8, -20, -6, 1, 9, 11, 3, -2, -14, -11, -2, 1, -4, -6, 4, 16, -32, -35, -6, -5, 6, -5, -78, -65, -14, -21, -25, -37, 5, -11, -2, -6, -32, -46, -2, 7, 2, -11, -1, -43, -39, 2, 0, -5, -16, -38, -2, 17, 3, -13, -29, -26, 7, 31, 34, -14, 3, -13, 16, 19, 36, -13, 25, -2, -22, -17, -42, -4, 13, -5, -28, -37, -22, -32, -8, -3, -17, -13, 1, -1, -14, -12, -8, -7, -2, -14, -22, -19, -36, -27, -14, -1, 11, 10, -22, -26, -51, 6, -26, -10, -1, -8, -16, 8, -7, -22, -3, 4, 9, 0, -3, -9, 1, -11, 1, -8, -9, 2, -1, -23, -5, 3, 19, 16, -38, -57, 5, -6, -1, 7, -67, -61, -15, -24, -29, -54, -16, -19, 1, -26, -30, -44, -10, 11, 9, -26, -29, -30, -35, 3, 5, -9, -14, -9, 11, 36, 5, -7, -10, -20, -26, -17, 14, -4, -9, 2, -56, -115, -41, -13, -26, -26, -43, -29, -24, 3, -10, -11, 4, 9, 13, -13, -10, 12, 0, 1, 7, -10, -18, -13, -1, 2, 2, -28, -21, -12, -6, -1, 7, -22, -39, 0, 8, 15, 7, 3, 13, -6, -4, -17, -13, -5, 13, 3, -7, -12, -14, -2, 11, 48, 8, -2, -11, -12, -2, -2, 10, 4, 11, -22, -30, -11, 31, 52, 36, -26, -39, -24, -41, -25, -8, -9, -18, -16, -32, -49, -30, -2, -2, 0, 9, -19, -13, -5, -3, 22, 11, 9, -10, -3, -8, -13, 4, -17, -1, -16, 16, 1, -25, -45, -10, -3, 7, 11, -33, -15, -30, -6, -18, -11, -13, -2, -6, -10, -15, 10, 9, -9, 11, 4, -10, -2, 3, -3, 7, -15, -27, -21, -4, 5, 9, -18, -13, 11, 22, 33, 23, -10, 2, 9, -10, -16, -1, -12, 4, -20, -31, -28, -19, 0, 14, -7, -8, -2, -11, -14, -17, -2, -5, -14, 1, -3, -5, -13, 6, -19, -10, -5, 2, 17, 13, -14, -15, -22, -27, -25, -50, 5, -11, -15, -38, -29, -31, -6, 2, -10, -13, -11, 14, 7, -4, -10, -8, 16, 25, 5, 0, -15, -19, -26, -17, -9, -4, -28, -30, 4, 13, 11, 2, -20, -17, -8, -6, 23, 9, -8, -6, -17, -14, -11, -9, 0, 14, 14, 3, -22, -1, 0, 1, 18, 15, -23, -12},
|
||||
{-6, 23, 41, 19, 0, 3, 7, 18, 18, -23, -50, -11, 5, 16, -6, -40, -55, -16, 1, 11, 6, -39, -14, 4, 0, -8, -9, -10, 6, -10, -7, -13, -16, -11, -3, -10, -2, -5, 0, 13, -10, -6, -2, -6, 9, 18, -22, -5, -6, -6, 22, 11, -17, -9, -23, -34, -4, -24, -31, -9, -42, -80, -48, -23, 13, -2, -12, -23, -24, -7, -4, -4, -14, -16, -27, -40, -29, -12, -15, -22, -30, -5, 19, -2, -23, -51, -27, 37, 29, 5, -29, -70, -43, -7, -10, -22, -7, -45, -30, -25, -35, -4, -1, 0, 22, -1, -14, -5, -1, 1, -3, 1, 17, 1, -3, -21, -36, -17, 9, 3, -17, -41, -51, -16, 3, -31, -16, -28, -41, -17, -25, -15, -10, 4, -1, 2, 1, -17, -24, -13, 8, 20, -11, -24, 5, 23, 8, 2, 5, 0, -8, 8, 6, 1, -13, -27, 2, 4, 5, -37, -38, -13, -1, 6, -16, -20, 0, -5, -20, 3, -12, -14, 9, -5, -22, -21, -34, -50, -16, -3, 10, 8, 11, 24, 13, -1, 8, 6, 3, -6, -35, -12, 14, 10, 4, -25, -40, -10, -1, 11, -2, -26, -1, -5, -13, 10, -23, -41, -15, -7, -10, -4, -10, -49, -18, -1, 8, 4, -27, -27, 10, 15, -1, -30, -65, -30, 17, 15, -6, -37, -79, -28, 15, -26, -7, -18, -45, -24, -34, -11, -11, -1, -6, 3, -8, -15, -14, -7, 18, -3, -12, -13, -9, -15, -13, -8, 11, 20, -12, -7, -13, -23, -21, -9, 0, 8, -8, -8, -48, -17, -6, 7, -13, 8, -11, 15, -6, -7, 13, 8, 12, -8, -6, -20, -21, -19, -23, -17, 3, 14, 25, 21, 10, 4, 2, 5, 6, -32, -55, -2, 11, 17, 2, -34, -43, -3, 6, 11, 11, -27, -11, 2, -11, 7, -14, -40, -18, 1, -12, -23, -51, -39, -6, -3, 5, 18, 22, 10, 12, -4, 6, 15, 6, -7, -32, -25, -7, 1, -2, -32, -53, -18, -13, 2, -11, -39, -4, 5, -15, -2, 3, 9, 0, 0, -2, -5, -41, -39, -13, -6, 1, -3, -27, -19, -18, -9, -19, -26, -32, -33, -11, -14, -4, -35, -13, 32, 21, 15, -32, -41, -21, 24, 10, -25, -24, -56, -16, 10, -11, -16, -3, -15, -11, -3, -11, 3, 2, -18, -7, -3, -6, -8, -14, -10, 22, 28, 4, -15, -11, -17, 16, 27, -9, -1, -26, -44, -9, -21, -46, -24, -26, -60, -24, -17, 20, -6, -4, -20, -26, -5, -10, -1, 0, 7, 0, -3, 10, 15, -7, -1, -20, -50, -44, -27, 3, 8, 4, -42, -20, 1, -8, 1, 10, -4, -8, 11, -15, 9, 19, 4, -4, -14, 0, -13, -29, -21, -16, 1, 2, -3, -13, -3, 17, 11, -14, -24, -37, -33, -21, -10, -16, -29, -25, -28, -16, -19, -8, -13, -25, -4, 21, -5, -19, -12, 14, 21, 6, -22, -14, -47, -39, -21, -18, -6, -3, -2, 2, 11, 0, -13, -8, -4, 16, 33, 11, -4, 0, -2, 19, 14, -7, -5, -7, -17, 16, -17, -32, -12, -21, -70, -44, -32, -20, -7, -10, -41, -42, -12, -3, -2, -3, 1, -19, -22, -4, 4, -8, -27, -38, -39, -36, -18, -11, -33, 0, 17, 3, 12, -34, -42, -17, 13, -6, -29, -20, -55, -1, 13, -8, -13, 1, -17, -20, -3, -2, -1},
|
||||
{-6, 0, -21, -20, -10, -15, -10, -20, -20, -4, -6, -3, -8, 0, 60, 3, -6, -1, 7, 53, 12, -24, -10, -7, 9, 11, 5, 0, -7, -12, 1, 22, 15, -3, -9, -12, -7, -4, -1, -37, -41, -14, -13, -29, -43, -30, -6, -11, -19, 12, 16, -6, -16, -19, -11, 43, 3, 25, -3, -19, -3, -4, -7, -3, -8, 6, 19, 3, -29, -23, -17, -10, -11, -1, 1, 7, -2, -5, 5, 27, 46, 13, -24, -2, 6, 31, -4, -40, -6, -10, -18, -16, -17, 8, -9, -20, -2, -14, -42, 8, -6, -26, -26, -45, -37, -17, -12, -10, 6, -1, -7, -14, -10, 0, 2, 33, 34, 27, -11, -22, 7, 5, -12, 21, 11, -12, -8, -13, -29, -25, 0, -19, -28, -34, -27, -17, 7, -2, 8, -37, -43, -27, -43, -18, 1, 0, -34, -19, -11, -9, -12, -46, -28, 9, 20, -12, -8, -16, -26, -8, -16, -5, -10, -8, -16, -2, 6, -12, -20, -32, -5, -9, -21, -5, 11, 14, 3, 11, -25, -7, -7, -6, -29, -38, -18, -10, -12, 2, -34, -52, -18, -1, -13, -22, -34, 45, 0, -8, -20, -9, -18, 52, 19, -3, -24, -23, 1, 16, -11, 6, 7, -8, 24, 23, -18, 4, 3, -7, -4, -8, 7, 6, 0, 22, 26, 24, -16, -25, 8, 12, 1, 12, -17, -29, -9, 11, -27, -29, 11, -22, -20, -28, -31, -18, -20, -18, -7, -35, -44, -23, -31, -22, -1, 1, -8, -9, -17, -3, 19, 36, 5, -23, -18, -18, -3, 1, -3, 5, 0, 6, 1, -11, -44, -45, 3, -4, -5, -15, -35, -31, -29, -20, 8, -3, 12, -3, -13, -17, 0, -20, -18, -47, -24, -7, -11, -13, -15, -2, -3, -8, -20, -17, -32, 21, 5, -6, -27, -25, -4, 24, 20, -1, -22, -35, 14, 30, -16, 4, 21, 10, 20, 20, -15, 0, -3, -4, -24, -14, -8, -12, 0, -38, -15, -6, 15, 1, 10, 5, 0, -8, 1, -6, 1, -2, -42, -2, 0, 0, -8, -19, -3, -30, -18, -17, 17, 18, -8, 12, -15, -3, -4, 4, -16, -7, -15, -31, 1, 8, 10, 2, 5, -13, 8, 23, -2, -34, -6, -11, -7, 6, -28, -43, 7, -12, -1, -8, -33, -46, -49, -22, 17, -11, -56, -20, -21, -8, -11, -10, -8, -9, -19, -13, -8, -29, -14, -2, 5, -13, -16, 14, 11, -22, 1, -15, -10, 29, 16, -11, -9, -9, 3, -7, -6, -10, -7, 9, 9, 5, -31, -22, -24, -6, 1, -10, -15, -11, -28, -13, 28, 36, 37, 19, 8, -3, 13, -12, -30, 12, -6, -6, -12, -30, -40, 5, -4, -2, -9, -33, -19, -20, -26, -25, 6, 9, 11, 8, -8, -5, 1, 0, -16, -25, -31, -6, 14, 11, 7, 17, -3, -16, 12, 21, -10, 0, -13, -20, -1, -20, -52, -14, 22, -2, -27, -62, -31, -26, -28, -17, 9, 2, -49, -32, -36, -21, -7, -8, -20, -28, -29, -18, -15, -32, -46, -48, -3, -12, -30, -16, -4, 14, -18, -20, -8, 22, 20, 48, -17, -24, -13, 3, 16, 31, 5, 3, 3, 10, -6, -5, 1, -5, -7, -7, -20, -35, -31, -27, -6, 6, 16, 19, -2, -11, -8, 17, -22, -34, -15, -8, -3, -13, -25, -13, 12, -12, -16, -21, -47, -36, -33, -22, 27, -4, -53, -33, -22, -13},
|
||||
{-5, -3, -24, -22, -25, -25, -7, -8, -50, -37, -9, -19, 6, -7, -19, -21, 4, -5, 4, -28, -3, -7, -11, -8, -1, 4, -28, -9, 6, -3, 4, -42, -34, -8, -7, -7, 1, -2, 4, -1, 10, 9, 11, 13, -17, -43, -18, 1, -10, -44, -80, -12, 10, -12, -10, -10, -21, -15, -29, 14, -4, -14, -61, -24, -6, 5, -26, -56, -40, 23, -6, 2, 19, 2, 0, -10, -2, 0, 12, -18, -20, -31, -15, 8, 14, 1, 4, -33, -42, -10, 3, -27, -92, -20, 17, 11, 1, -64, -50, -26, -28, 14, 17, 10, -1, -12, 3, 17, 2, -17, -5, -10, 0, 5, -1, -9, -5, -7, -5, 5, -4, -9, 1, -11, 10, -3, -6, -8, -8, 14, 4, 4, -21, -30, -32, -21, -27, -24, -11, 7, 10, 2, -18, -5, 1, -2, 12, -8, -6, -13, 3, 6, -14, -8, -10, -3, -2, -14, -4, 17, 44, 9, -16, 18, 37, -7, -50, -18, -13, 2, -11, -7, -3, -7, -6, -45, -9, 20, 8, -8, 1, 5, 1, 0, 5, 6, -8, 4, -14, -24, -16, -7, -2, -7, -12, -38, -9, -12, -10, 2, 9, -58, -46, 2, 3, 4, -4, -34, -8, -2, 0, -11, -7, -43, -18, 2, 5, -14, -8, 1, -9, -2, 0, -30, -6, -9, -7, -11, -2, -9, -13, -15, 5, -6, -6, 2, -4, 16, 14, -4, -13, -38, -24, -11, -27, -27, -9, -8, 5, 8, -4, -9, -2, -5, 1, 4, -17, -7, -6, -26, -9, 11, 12, -5, 2, 34, 22, -8, -10, 1, -18, -17, 28, 13, -9, -15, -20, -17, -1, 4, -8, -15, -3, 8, 3, -26, -9, 1, -5, -4, -26, -19, 8, -5, -2, -7, -28, -29, -11, 8, -11, -7, -22, -32, -21, -3, -13, -11, 6, -59, -44, -4, 4, -7, -1, -43, -3, -4, -7, -24, -37, -36, -12, -1, 1, 3, 17, 5, -8, -10, -10, 6, -18, -11, 6, -9, -8, -26, -15, 19, 30, 14, -7, 24, 39, -23, -41, -30, -20, 5, -10, -12, 2, -3, -6, -31, -25, -3, 15, -8, -1, 4, 5, 13, 12, -2, -6, 5, -6, 0, 18, 18, -15, -8, 4, -3, -16, -25, -15, -12, -20, -10, 1, -1, -20, -40, -37, -19, -14, -21, -17, -38, 4, -20, -38, -7, -4, 3, -6, -3, 11, 5, 0, 0, -20, -23, -13, -4, -9, -32, -60, -8, 10, -4, -2, 2, -27, -37, -24, 12, 0, -38, -36, -35, -25, -12, -13, -63, -44, 16, 18, 3, 1, -17, -10, -29, -31, -11, -12, -14, -37, -37, -17, -2, 5, 8, -9, -11, -26, 3, -17, -33, -16, -10, -25, -16, -10, -5, -30, -12, 1, 0, -7, 13, 8, -9, 15, 4, -1, -12, 9, 16, 5, 9, -4, -23, -15, 4, 13, 7, -8, -27, -24, -3, 16, 19, -29, -31, -12, -12, 1, -35, -14, -22, -5, 17, -12, -23, -17, 2, 24, 20, 7, -1, 9, 5, -1, -10, -9, 7, 9, 12, -25, -43, -42, -6, 5, -29, -68, -28, -39, 2, 4, -2, -43, -43, -46, 24, 15, 3, -59, -34, -20, 22, 2, -43, -113, -32, 9, 19, -7, -5, 16, 7, -8, -1, -7, 3, -10, -21, 2, 3, -5, -27, -3, 13, -13, -15, -10, -6, -15, 3, -1, -6, -10, -39, -38, -17, -11, -11, -28, -47, 17, 9, -5, -3},
|
||||
{-4, -10, -26, -36, -24, -10, -2, -28, -60, -26, -15, -2, 5, -15, -63, 15, 14, 3, 1, -28, -49, 22, 12, 7, -6, -26, -4, 6, -2, -5, 5, 1, 20, -8, -1, 4, -14, 1, -1, -7, -34, -1, 8, 11, 23, -12, -77, -12, -12, -30, -47, 1, 3, -15, -41, -78, -46, 2, -15, -7, -25, -6, 9, -6, -14, -7, 19, 23, 10, -36, -12, -17, -1, -6, -3, 8, 3, 2, -4, -39, -42, -18, 5, 3, -33, -57, -38, -35, -24, -15, 2, 8, 25, -66, -66, -4, -12, 17, 16, -9, -26, -6, -12, -10, -17, -11, 14, -3, -3, -6, -14, -9, -12, 11, -22, -20, -1, -11, -6, -22, 2, -5, 5, -23, -23, -31, -5, 1, 5, 22, -30, -28, -26, -7, 17, -12, -34, -21, -15, -16, -17, -24, -26, -6, -2, -18, 12, -18, -13, -16, -6, 9, 6, -7, -29, -38, 13, -10, -23, 18, -6, -23, -14, -26, -45, 12, 9, -30, -10, -14, -14, -10, -25, 0, 4, 6, 2, -9, 1, -3, -2, -8, -25, -17, -11, -4, -5, -10, -25, -61, -49, 3, 3, 0, -25, -43, -14, -5, -9, -8, -50, -25, -2, 2, -15, -15, -28, 3, 7, 6, -1, -2, 24, 21, 27, -9, 9, 5, -8, 9, -6, 3, -15, -64, -8, 6, 0, -17, -10, -41, -4, -8, -14, -45, -14, -13, 0, 10, -42, -30, -16, 15, 13, -22, -22, -24, -25, -17, -25, -29, -18, -5, -1, 3, 24, 9, -6, -3, -13, -47, -40, 9, 4, 0, -7, 3, -20, -8, -4, 8, -9, 23, -2, -5, 7, 1, -6, -8, -11, -28, -8, -14, 6, -15, 6, 0, -2, 8, -7, -1, -60, -70, -30, 0, 3, -5, -40, -56, -45, -9, 5, -1, -29, -19, -3, -5, -15, -15, -52, 0, 3, 2, -24, -40, -22, 11, 2, 4, 1, 1, 21, 33, 23, 5, -2, -13, 5, -19, -25, -13, 0, 21, -2, -26, -19, -34, 2, -17, -36, 22, -6, -15, -13, -31, -52, 13, 8, -30, -3, -5, -17, -10, -6, -14, -4, 8, -5, -11, -21, -1, -11, -19, 12, 10, -2, -25, -4, -5, -4, 7, 12, -7, -26, -36, -21, -11, -22, -31, -47, -27, 14, -7, -61, -48, -24, 5, 11, -22, -62, 4, 11, 4, -30, -12, 21, 10, -2, 0, 4, -12, -21, -13, 9, 5, 12, -28, -58, -17, -16, -31, -36, 6, -8, -17, -43, -57, -27, -13, -2, -10, -18, 7, 11, 4, 1, -11, 8, 20, 1, -18, -10, -20, -7, -16, -18, -31, -14, -9, -17, -49, -66, -4, 10, -8, 5, 0, -20, 25, 16, -2, 1, 11, -40, -5, 7, -18, -1, -17, -45, -19, -1, -14, 1, -4, 5, 22, 10, 11, 3, -17, -9, -4, -16, -9, -13, -15, 1, 0, 8, -21, -4, -13, 14, 15, -16, -18, -17, -1, 22, -7, -62, -38, -11, -5, 1, -46, -48, -20, -4, -6, -21, -19, -4, 5, -2, -3, -18, -20, -18, -11, 5, 16, 8, -61, -62, -3, 0, -8, -53, -8, -14, -1, -19, -79, -86, -29, 22, 5, -3, -12, -15, -24, 35, 1, 5, 15, 19, -2, -10, -14, -3, -17, 12, 13, -10, -26, -5, 2, -13, 4, 9, 2, -18, -27, -13, 27, 4, -19, -53, -29, 10, -31, -44, -37, -24, 9, 8, -48, -42, -8, 9, 9, -28, -28, 13, 22}
|
||||
};
|
||||
|
||||
int32_t b_conv1[6] = {101, 113, 26, 14, 127, 61};
|
||||
|
||||
int32_t b_conv2[16] = {70, -89, 4, 48, 24, 127, -12, -74, 77, 36, -15, 13, -45, 21, 30, -28};
|
||||
|
||||
int32_t b_fc1[10] = {-77, -48, -24, -90, -35, -48, -89, -44, 127, 10};
|
||||
|
||||
#endif // __WEIGHTS__H__
|
||||
11
sdk/software/examples/pinball_game/Makefile
Normal file
11
sdk/software/examples/pinball_game/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
TARGET = pinball_game
|
||||
|
||||
CFLAGS += -O3 -g
|
||||
|
||||
C_SRCS := $(wildcard ./*.c )
|
||||
|
||||
OBJDIR = obj
|
||||
COMMON_DIR = ../../bsp
|
||||
GCC_DIR=../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../toolchains/picolibc
|
||||
include ../../bsp/common.mk
|
||||
249
sdk/software/examples/pinball_game/main.c
Normal file
249
sdk/software/examples/pinball_game/main.c
Normal file
@@ -0,0 +1,249 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common_func.h"
|
||||
#include "dvi.h"
|
||||
#include "seg7.h"
|
||||
#include "led.h"
|
||||
#include "core_time.h"
|
||||
|
||||
//BSP板级支持包所需全局变量
|
||||
unsigned long UART_BASE = 0xbf000000; //UART16550的虚地址
|
||||
unsigned long CONFREG_TIMER_BASE = 0xbf20f100; //CONFREG计数器的虚地址
|
||||
unsigned long CONFREG_CLOCKS_PER_SEC = 50000000L; //CONFREG时钟频率
|
||||
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
|
||||
|
||||
|
||||
int Ball_x = 400;
|
||||
int Ball_y = 100;
|
||||
int Ball_r = 5;
|
||||
|
||||
volatile int Plane_x = 400;
|
||||
int Plane_y = 400;
|
||||
int Plane_l = 100;
|
||||
int Plane_w = 5;
|
||||
|
||||
// ball move direction
|
||||
int Ball_dx = 2;
|
||||
int Ball_dy = 2;
|
||||
|
||||
// ball move direction
|
||||
int Plane_dx = 20;
|
||||
|
||||
int score = 0;
|
||||
|
||||
volatile int delay_time = 0;
|
||||
|
||||
void Timer_IntrHandler(void);
|
||||
void Button_IntrHandler(unsigned char button_state);
|
||||
|
||||
void showGameOver(void);
|
||||
|
||||
int chooseFlag = 1;
|
||||
|
||||
volatile int flag = 1;
|
||||
|
||||
void InterruptInit(void)
|
||||
{
|
||||
// Enable button and timer Interrupt
|
||||
RegWrite(0xbf20f004,0x0f);//edge
|
||||
RegWrite(0xbf20f008,0x1f);//pol
|
||||
RegWrite(0xbf20f00c,0x1f);//clr
|
||||
RegWrite(0xbf20f000,0x1f);//en
|
||||
|
||||
RegWrite(0xbf20f104,25000000);//timercmp 500ms
|
||||
RegWrite(0xbf20f108,0x1);//timeren
|
||||
}
|
||||
|
||||
void showGameOver(void);
|
||||
|
||||
void chooseTime(void)
|
||||
{
|
||||
printf("Please Choosetime !!\n");
|
||||
while (flag);
|
||||
printf("Choosetime:%d\n",delay_time);
|
||||
chooseFlag = 0;
|
||||
setSegNum(0,0,0,0);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
InterruptInit();
|
||||
|
||||
chooseTime();
|
||||
|
||||
while (1) {
|
||||
|
||||
DVI_Draw_Rect(Plane_x,Plane_y,Plane_l,Plane_w);
|
||||
|
||||
DVI_Draw_SQU(Ball_x,Ball_y,Ball_r);
|
||||
|
||||
delay_ms(delay_time);
|
||||
|
||||
// refresh place
|
||||
Ball_x += Ball_dx;
|
||||
Ball_y += Ball_dy;
|
||||
|
||||
delay_ms(delay_time);
|
||||
|
||||
if(Ball_y < 2)
|
||||
{
|
||||
Ball_y = 2;
|
||||
Ball_dy = -Ball_dy;
|
||||
}
|
||||
|
||||
if(Ball_y > 600)
|
||||
{
|
||||
Ball_y = 600;
|
||||
Ball_dy = -Ball_dy;
|
||||
}
|
||||
|
||||
if(Ball_x < 2)
|
||||
{
|
||||
Ball_x = 2;
|
||||
Ball_dx = -Ball_dx;
|
||||
}
|
||||
|
||||
if(Ball_x > 800)
|
||||
{
|
||||
Ball_x = 800;
|
||||
Ball_dx = -Ball_dx;
|
||||
}
|
||||
|
||||
if( Ball_y > 410 )
|
||||
break;
|
||||
|
||||
if((Plane_y - Ball_y) < 2 && (Ball_x > (Plane_x - Plane_l)) && (Ball_x < (Plane_x + Plane_l)))
|
||||
{
|
||||
Ball_dy = -Ball_dy;
|
||||
score++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
showGameOver();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void HWI0_IntrHandler(void)
|
||||
{
|
||||
unsigned int int_state;
|
||||
int_state = RegRead(0xbf20f014);
|
||||
|
||||
if((int_state & 0x10) == 0x10){
|
||||
Timer_IntrHandler();
|
||||
}
|
||||
else if(int_state & 0xf){
|
||||
Button_IntrHandler(int_state & 0xf);
|
||||
}
|
||||
}
|
||||
|
||||
void Timer_IntrHandler(void)
|
||||
{
|
||||
if (!chooseFlag)
|
||||
{
|
||||
// refreshing the DVI output
|
||||
if (score > 9)
|
||||
{
|
||||
setSegNum(1,score/10,1,score%10);
|
||||
}else{
|
||||
setSegNum(0,0,1,score);
|
||||
}
|
||||
}
|
||||
RegWrite(0xbf20f108,0);
|
||||
RegWrite(0xbf20f108,1);
|
||||
}
|
||||
|
||||
void Button_IntrHandler(unsigned char button_state)
|
||||
{
|
||||
if (chooseFlag)
|
||||
{
|
||||
if (button_state & 0b1)
|
||||
{
|
||||
delay_time++;
|
||||
|
||||
if (delay_time > 20)
|
||||
{
|
||||
delay_time = 20;
|
||||
}
|
||||
printf("button1\n");
|
||||
RegWrite(0xbf20f00c,0x1);//clr
|
||||
|
||||
}else if (button_state & 0b1000)
|
||||
{
|
||||
delay_time--;
|
||||
if (delay_time < 1)
|
||||
{
|
||||
delay_time = 1;
|
||||
}
|
||||
printf("button4\n");
|
||||
RegWrite(0xbf20f00c,0x8);//clr
|
||||
}else if (button_state & 0b100)
|
||||
{
|
||||
flag = 0;
|
||||
printf("button3\n");
|
||||
RegWrite(0xbf20f00c,0x4);//clr
|
||||
}else{
|
||||
printf("button2\n");
|
||||
RegWrite(0xbf20f00c,0x2);//clr
|
||||
}
|
||||
|
||||
setSegNum(1,delay_time/10,1,delay_time%10);
|
||||
|
||||
}
|
||||
|
||||
if (!chooseFlag)
|
||||
{
|
||||
|
||||
if (button_state & 0b1)
|
||||
{
|
||||
Plane_x += Plane_dx;
|
||||
if (Plane_x + Plane_l > 800)
|
||||
{
|
||||
Plane_x = 800 - Plane_l;
|
||||
}
|
||||
RegWrite(0xbf20f00c,0x1);//clr
|
||||
}else if (button_state & 0b1000)
|
||||
{
|
||||
Plane_x -= Plane_dx;
|
||||
if (Plane_x - Plane_l < 0)
|
||||
{
|
||||
Plane_x = Plane_l;
|
||||
}
|
||||
RegWrite(0xbf20f00c,0x8);//clr
|
||||
}else if (button_state & 0b0100){
|
||||
RegWrite(0xbf20f00c,0x4);//clr
|
||||
}else if (button_state & 0b0010){
|
||||
RegWrite(0xbf20f00c,0x2);//clr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void showGameOver(void)
|
||||
{
|
||||
|
||||
printf("GameOver\n");
|
||||
|
||||
while (1)
|
||||
{
|
||||
setLedPin(0b1000000000000001);delay_ms(50);
|
||||
setLedPin(0b1100000000000011);delay_ms(50);
|
||||
setLedPin(0b1110000000000111);delay_ms(50);
|
||||
setLedPin(0b1111000000001111);delay_ms(50);
|
||||
setLedPin(0b1111100000011111);delay_ms(50);
|
||||
setLedPin(0b1111110000111111);delay_ms(50);
|
||||
setLedPin(0b1111111001111111);delay_ms(50);
|
||||
setLedPin(0b1111111111111111);delay_ms(50);
|
||||
setLedPin(0b1111111001111111);delay_ms(50);
|
||||
setLedPin(0b1111110000111111);delay_ms(50);
|
||||
setLedPin(0b1111100000011111);delay_ms(50);
|
||||
setLedPin(0b1111000000001111);delay_ms(50);
|
||||
setLedPin(0b1110000000000111);delay_ms(50);
|
||||
setLedPin(0b1100000000000011);delay_ms(50);
|
||||
setLedPin(0b1000000000000001);delay_ms(50);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user