Post on 19-Mar-2020
1
UNIVERSIDADE FEDERAL DO RIO GRANDE DO SULPROGRAMA DE PÓS-GRADUAÇÃO EM COMPUTAÇÃO
CMP237 – ARQUITETURA E ORGANIZAÇÃO DE PROCESSADORES
On the feasibility of adaptingthe FemtoJava microcontroller
for the CIL instruction set
Felipe Ghellar
July 2006
2
Summary● The Java Platform
● Java for Microcontroller Applications
● FemtoJava and Sashimi
● Common Language Infrastructure
● Java vs. Common Intermediate Language
● CIL for Microcontroller Applications
● Adapting FemtoJava and Sashimi
● Conclusions
● References
3
The Java Platform
JavaSource
Compiler
JavaOpcodes
JavaVirtualMachine
● Java language inspired on C/C++
● Use of a virtual machine
● Use of an intermediate language
● VM and IL designed to support one
language
4
Java for µController Applications● Advantages of a Java-based microcontroller
● Use of a single high-level language
● Use of standard tools for application validation
● Increased portability an code reuse
● Shorter time-to-market
● Only needed hardware is synthesized
● And many more...
5
The FemtoJava Microcontroller● Targeted to FPGAs
● Executes Java opcodes
● Memory-mapped I/O● Extended intructions for memory access
● Timers, interrupts
● Integer operations only
● No dynamic object creation
6
The Sashimi Design Flow● Restricted Java code
● Sashimi classes
● Standard Java compiler
● Standard Java VM
● Opcode analysis
● Opcode adaptation● Opcode substitution
● Sashimi libraries
● ASIP/SW generation
● Standard VHDL tools
● Standard FPGA tools
7
● C# language inspired on C/C++/Java
● Use of a virtual machine
● Use of an intermediate language
● VM and IL designed to support many
languages
Common Language Infrastructure
Compilers
CommonIntermediateLanguage
VirtualExecutionSystem
C# FortranVB PythonC DelphiC++ ...Java
8
Common Language Infrastructure
● Common Language Infrastructure
● Common Type System
● Common Language Specification
● Virtual Execution System
● Common Intermediate Language
● Microsoft, HP, Intel
● Standardized● ECMA 335
● ISO/IEC 23271
JavaSource
Compiler
JavaOpcodes
JavaVirtualMachine
Compilers
CommonIntermediateLanguage
VirtualExecutionSystem
C# FortranVB PythonC DelphiC++ ...Java
9
Java vs. CIL● Both VMs are stack based
● Integer values are sign-extended in the stack
● Java opcodes are one byte, CIL's can be longer
● Java has a Constant Pool, CIL uses immediates only
● Java immediates are big-endian, CIL's are little-endian
● CIL instructions are not typed
● CIL was not designed to be interpreted
● CIL provides instructions for memory access
10
CIL for µController Applications● Advantages of a CIL-based microcontroller
● All the advantages of a Java-based one, plus:
● Choice of high-level language (e.g. Java)
● Interoperability among high-level languages
● Use of a standardized instruction set
11
The “FemtoCIL” Microcontroller● Targeted to FPGAs
● Executes CIL opcodes
● Memory-mapped I/O● Native intructions for memory access
● Timers, interrupts
● Integer operations only
● No dynamic object creation
12
From FemtoJava to “FemtoCIL”● Main differences:
● In the architecture:● Instruction set
● In the organization:● Instruction length
● Endianess
● Typeless instructions
● In the design tool:● Sashimi
13
Instruction Set● CIL opcodes form a superset of Java opcodes
● Most supported instructions have CIL equivalents● Specialized instructions can be implemented in software
● dup2, swap, iinc, iflt, ifgt...
● Easy to implement
14
Instruction Set● Loading constants
Immediatebipushsipush
Constant Poolldcldc_wldc2_w
Null Referenceaconst_null
Short Formsiconst_m1iconst_0iconst_1iconst_2iconst_3iconst_4iconst_5lconst_0lconst_1fconst_0fconst_1fconst_2dconst_0dconst_1
Immediateldc.i4.sldc.i4ldc.i8ldc.r4ldc.r8
Null Referenceldnull
Short Formsldc.i4.m1ldc.i4.0ldc.i4.1ldc.i4.2ldc.i4.3ldc.i4.4ldc.i4.5ldc.i4.6ldc.i4.7ldc.i4.8
Java CIL
15
Instruction Set● Loading local variables and array elements
Immediate[ilfda]load
Short Forms[ilfda]load_0[ilfda]load_1[ilfda]load_2[ilfda]load_3
Array sizearraylength
Array elemsialoadlaloadfaloaddaloadaaloadbaloadcaloadsaload
Immediateldloc.sldloc
Short Formsldloc.0ldloc.1ldloc.2ldloc.3
Array sizeldlen
Array elemsldelemldelem.i1ldelem.i2ldelem.i4ldelem.i8ldelem.u1ldelem.u2ldelem.u4ldelem.u8ldelem.r4ldelem.r8ldelem.refldelem.i
Java CIL
16
Instruction Set● Storing local variables and array elements
Immediate[ilfda]store
Short Forms[ilfda]store_0[ilfda]store_1[ilfda]store_2[ilfda]store_3
Array elemsiastorelastorefastoredastoreaastorebastorecastoresastore
Immediatestloc.sstloc
Short Formsstloc.0stloc.1stloc.2stloc.3
Array elemsstelemstelem.i1stelem.i2stelem.i4stelem.i8stelem.r4stelem.r8stelem.refstelem.i
Java CIL
17
Instruction Set● Arithmetic and logic
Arithmetic[ilfd]add[ilfd]sub[ilfd]mul[ilfd]div[ilfd]rem[ilfd]negiinc
Logic[il]shl[il]shr[il]ushr[il]and[il]or[il]xor
Arithmeticaddsubmuldivremneg
Logicshlshrshr.unandorxor
Java CIL
18
Instruction Set● Branching and control flow
Zero/Nullifeqifneifltifleifgtifgeifnullifnonull
Othersgoto[ilfda]returnreturn
Two Valuesif_icmpeqif_icmpneif_icmpltif_icmpleif_icmpgtif_icmpgeif_acmpeqif_acmpne
Zero/Nullbrfalsebrtrue
Othersbrreturn
Two Valuesbeqbne.unbltblebgtbge
Java CIL
19
Instruction Set● Classes, methods etc.
Class/Method
getstaticputstatic
getfieldputfield
invokevirtualinvokespecialinvokestaticinvokeinterface
checkcastinstanceof
Class/Method
ldsfldstsfld
ldfldstfld
callcallvirtjmp
isinst
Java CIL
20
Instruction Set● Stack, memory etc.
Stackpoppop2dupdup2dup_x1dup_x2dup2_x1dup2_x2swap
Othersnop(sleep)
Memory(restore_idx)(save_idx)(load_idx)(store_idx)
Stackpopdup
Othersnop
Memoryldobjstobj
cpobjinitobj
cpblkinitblk
Java CIL
21
Instruction Length● Opcodes can be one or more bytes long
● Worst case: extra cycle for Multicycle, bubble for Pipeline
● All currently supported instructions use only one byte
● CIL can have longer immediates than Java● Worst case: extra cycles for Multicycle, bubble for Pipeline
● Possible solution for Pipeline:● Resize pre-fetch buffer
IF ID OF EX WB
22
Endianess● Java immediates are big-endian
● Most significant byte comes first
● CIL immediates are little-endian● Least significant byte comes first
● Trivial solution: Adapt VHDL code● Easy to implement
● No penalties expected
Value:0x1234
Java:op 0x12 0x34
CIL:op 0x34 0x12
23
Typeless Instructions● OK for now, but trouble for floating point support
● Java's iadd and fadd both map to CIL's add
● Trivial solution:● Never add floating point support
● Java's iadd maps 1:1 to CIL's add
● Other solution:● Sashimi maps add to iadd or fadd based on operators
● Needs extended instructions
● Better solution:● Keep type information in the stack
● Operators can be routed to proper execution unit
● Small area penalty
24
Adapted Sashimi Design Flow● Any language, same restrictions
● Sashimi classes in CIL
● Standard CIL compiler
● Standard CIL VM
● CIL Opcode analysis
● CIL Opcode adaptation● Opcode substitution
● Sashimi libraries in CIL
● ASIP/SW generation
● Standard VHDL tools
● Standard FPGA tools
<número>
Conclusions● Adaptation is feasible
● With relatively little effort
● And brings advantages● Freedom of choice of high-level language
● Interoperability among high-level languages
● Each developer can use a different one, including Java
● Standardized instruction set
● Instructions for memory access are no longer extensions
● And are supported by standard tools
● With small area penalty
● And probably no performance penalty
<número>
References● Common Language Infrastructure
● Ecma International. Standard 335 – Common Language Infrastructure. 2006.● Java
● T. Lindholm, F. Yellin. The Java Virtual Machine Specification. 1997.● FemtoJava and Sashimi
● S. A. Ito. Projeto de Aplicações Específicas com Microcontroladores Java Dedicados. 2000.
● S. A. Ito, L. Carro, R. Jacobi. Designing a Java Microcontroller to Specific Applications. 1999.
● S. A. Ito, L. Carro, R. Jacobi. System Design Based on Single Language and Single-Chip Java ASIP Microcontroller. 2000.
● S. A. Ito, L. Carro, R. Jacobi. Making Java Work for Microcontroller Applications. 2001.
● S. A. Ito, L. Carro. A Comparison of Microcontrollers Targeted to FPGA-Based Embedded Applications. 2000.
● S. A. Ito, L. Carro, R. Jacobi. Issues on Designing Embedded Aplications Targeted to a Java Microcontroller. 1999.
● Sashimi – Manual do Usuário v0.9. 2006.● Virtual Machines
● P. Sestoft. Abstract Machines in the Real World. 2002.● K. J. Gough. Stacking them up: a Comparison of Virtual Machines. 2001.
● Miscellanea● Various Wikipedia articles on Java and the CLI, mainly historic notes.