⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme.customops

📁 基于4个mips核的noc设计
💻 CUSTOMOPS
字号:
Introduction============This document describes how to add custom ops (user defined instructions)to lcc and Oink. Because lcc does not support inline assembly we have toapply a trick to achieve it. Step 1: find opcode space=========================Find space in the MIPS opcode space for the custom ops that you want toadd. Custom ops can have multiple operands but only one result. In order tosupply all operands, a custom op might be implemented by multiple instructionsthat pass all operands to the functional unit where the last instructiontriggers the functional unit to start the operation.Step 2: add patterns to minimips.md===================================Custom ops are generated by patterns of operations that are very unlikely tooccur in normal programs. An example of such a pattern is an integer loadof address 0x12344321 whose result is added to another integer and this resultis again subtracted from another integer. In minimips.md you have to specifythis pattern and tell what assembly code to generate for this pattern. Hereis the pattern for the described example:	magic_addr: CNSTP4      "%a"   is_magic_addr(a)	reg: SUBI4(reg, ADDI4(reg, INDIRI4(magic_addr)))        			"\t.word (%c<<11)|(%0<<21)|(%1<<16)|0x31\n"	int	is_magic_addr (Node p)	{	  return (int) p->syms[0]->u.c.v.p == 0x12344321 ? 0 : LBURG_MAX;	}Notice that the pattern has two arguments (reg) which correspond to thearguments of our custom op. When the pattern is detected, the compiler emitsthe '.word' directive which assembles the instruction for the custom op. Thedestination register (%c) and the two source registers (%0 and %1) are inserted at proper bit positions. Because we generate a '.word' directive instead of a new instruction, we don't have to modify the assembler thattranslates the assembly code of lcc to binary code.The patterns can have more than two register arguments and the assemblystring can contain multiple instructions separated by \n's to pass allarguments to the functional units.Step 3: compile lcc===================Check the BUILDDIR variable in 'makefile' and type 'make'Step 4: modify Oink===================Find out where to add your instruction in one of the tables in decode_tables.h.Replace the proper &&execute_DUMMY by your &&execute_MY_CUSTOM_OP. Add thecode to simulate your custom op to semantics.h. For example, to implementa custom op that computes the average of its arguments:	execute_MY_CUSTOM_OP:	{		RD = (RS + RT) / 2;		UPDATE_PC();		DONE;	}Step 5: compile Oink====================Type 'make oink'. Copy the resulting executable to your lccdir directory.Step 6: use the custom ops==========================The easiest way to use a custom op is to define a macro that expands intothe pattern of operations that triggers generation of the custom op. Forour example pattern this corresponds to:	#define average(a, b)       ((a) - ((b) + *(int *) 0x12344321))Now the custom op can be used by simple using the macro:	printf("average of 10 and 20 is %d\n", average(10, 20));Compiling and simulating this with lcc and oink modified as explained aboveshould lead to the desired result.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -