On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On...

26
1 UNIVERSIDADE FEDERAL DO RIO GRANDE DO SUL PROGRAMA DE PÓS-GRADUAÇÃO EM COMPUTAÇÃO CMP237 – ARQUITETURA E ORGANIZAÇÃO DE PROCESSADORES On the feasibility of adapting the FemtoJava microcontroller for the CIL instruction set Felipe Ghellar July 2006

Transcript of On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On...

Page 1: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 2: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 3: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 4: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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...

Page 5: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 6: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 7: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 8: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 9: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 10: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 11: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 12: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 13: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 14: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 15: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 16: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 17: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 18: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 19: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

19

Instruction Set● Classes, methods etc.

Class/Method

getstaticputstatic

getfieldputfield

invokevirtualinvokespecialinvokestaticinvokeinterface

checkcastinstanceof

Class/Method

ldsfldstsfld

ldfldstfld

callcallvirtjmp

isinst

Java CIL

Page 20: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 21: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 22: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 23: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 24: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

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

Page 25: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

<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

Page 26: On the feasibility of adapting the FemtoJava ...flavio/ensino/cmp237/felipe_apresentacao.pdf · On the feasibility of adapting the FemtoJava microcontroller ... S. A. Ito. Projeto

<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.