[virtmach] Inferno Dis VM Questions

virtmach@iecc.com virtmach@iecc.com
Mon, 11 Jun 2001 13:29:50 +0100


> Why are so many type conversions (eg. big to str, byte array to str, etc)
> and various string operations (eg. insert char into str) part of the byte
> code specification and not implemented as library routines?

one of the nice things about Inferno is that the binaries tend to be
very compact, and the programs quick, even in interpreted mode. i
usually ascribe this to the fact that primitive operations in the
language map very closely to VM operations.

it probably also has something to do with the fact that the high-level
language, Limbo, provides a set of primitive operations that perform
some non-trivial, but generally useful tasks. most of the

for instance, the real to string conversion converts from a IEEE double
into an exactly equivalent string, such that conversion in the other
direction is guaranteed to produce the original value.

Limbo is generally a language where "what you see is what you get".  a
library routine call looks like a library routine call; all language
primitives map directly to VM instructions (often a single
instruction).  this means that one gets a feeling of being fairly
"close to the metal" (despite being nothing of the sort!) as the timing
cost model for the language is straightforward and predictable.

for those that might be interested, i've attached a couple of files
giving some sort of idea of instruction counts in actual Inferno
programs. one gives the static count over 408 Dis modules (368169
instructions); the other gives the dynamic count when using the Limbo
compiler to compile itself (88658052 instructions)

  cheers,
    rog.

PS. "insert into string" is more akin to assigning to an array
index in the string than an actual "insert" operation, with
the single exception that assigning to an element one
beyond the end of the string extends the string by one character.
# percentage frequencies of Dis instructions (dynamic).
# task: limbo -g /appl/limbo/limbo.b
movw 13.9223
movp 12.6674
addw 6.96666
beqw 6.16293
bnew 5.78893
ret 4.86638
jmp 4.56816
indw 4.51639
frame 4.42891
call 4.42813
lea 4.12316
blew 2.72521
bgew 2.3197
indb 2.09632
case 1.69213
indx 1.62354
movb 1.48736
shlw 1.34974
bgtw 1.30828
andb 1.1821
bneb 1.15893
subw 1.10993
andw 0.879497
cvtbw 0.785712
movmp 0.763065
xorw 0.61039
cvtwb 0.543778
beqb 0.461277
mcall 0.439455
mframe 0.438684
orw 0.42189
movm 0.390381
shrw 0.389323
bltw 0.380327
orb 0.367635
divw 0.316533
indc 0.293142
modw 0.286654
new 0.263479
insc 0.247322
lena 0.220133
lenc 0.213013
cvtlw 0.131432
bgeb 0.120191
movl 0.113197
subl 0.0562715
bnec 0.0538327
cvtwl 0.0433452
shlb 0.035705
movf 0.0334703
mulw 0.0247968
slicela 0.0175908
bnel 0.0174069
addb 0.0173561
slicea 0.0171666
bltb 0.0154723
cvtwc 0.0130526
bltl 0.012501
bleb 0.00996969
bgtc 0.00991103
addc 0.00931429
beqc 0.00885518
bgtl 0.00878524
bgel 0.00878411
addl 0.0076978
newa 0.00343152
cvtca 0.0019628
bgec 0.0010378
slicec 0.000917103
bgtb 0.000746768
headp 0.000397073
tail 0.000263963
consp 0.000256067
indl 0.000171463
shll 4.7378e-05
mull 4.28658e-05
xorl 4.06097e-05
orl 3.38414e-05
load 3.27134e-05
blec 2.82012e-05
cvtcf 2.82012e-05
indf 2.48171e-05
lenl 1.57927e-05
shrl 1.24085e-05
beql 1.12805e-05
spawn 9.02438e-06
newcw 9.02438e-06
send 9.02438e-06
recv 9.02438e-06
consw 9.02438e-06
headw 9.02438e-06
cvtcw 9.02438e-06
cvtac 9.02438e-06
divf 2.2561e-06
# percentage frequencies of Dis instructions (static).
# Dis files: /dis/*.dis /dis/*/*.dis
movp	26.0533
movw	11.4705
lea	7.52127
frame	6.03093
mcall	4.92763
call	4.7375
jmp	4.08372
mframe	3.7567
ret	3.56412
beqw	2.56431
addw	2.52248
bnew	2.45757
addc	1.73453
indw	1.57591
subw	1.17555
blew	0.947391
movm	0.806152
lena	0.671974
bgew	0.669529
headp	0.632047
tail	0.619281
indb	0.59049
lenc	0.571477
indc	0.507104
indx	0.497869
new	0.414755
bnec	0.409595
newa	0.403076
load	0.393841
beqc	0.38189
andw	0.334357
bgtw	0.316159
mulw	0.310184
consp	0.305838
bltw	0.303665
slicea	0.290627
slicec	0.28601
case	0.275417
movmp	0.272158
cvtbw	0.248799
movb	0.247441
cvtwc	0.245539
movf	0.227613
send	0.214304
orw	0.179266
shrw	0.168401
indl	0.163783
cvtcw	0.16324
shlw	0.159981
cvtwb	0.144227
divw	0.143141
indf	0.129288
exit	0.12277
slicela	0.115165
cvtac	0.11435
spawn	0.109461
insc	0.104572
mulf	0.0861018
recv	0.0825708
cvtca	0.0801262
casec	0.0784966
newcp	0.0684468
addf	0.0670888
bneb	0.0638294
lenl	0.0638294
movl	0.0600268
subf	0.0567674
modw	0.0559526
consmp	0.055681
goto	0.0513351
headmp	0.0497054
cvtwf	0.0491622
beqb	0.048619
newcw	0.045088
alt	0.0391125
consw	0.0377544
andb	0.0339518
cvtwl	0.033137
cvtlw	0.0323221
xorw	0.030964
divf	0.0293344
newcmp	0.0160252
orb	0.0149388
addl	0.0143956
cvtfw	0.0130375
mspawn	0.0130375
bltb	0.0127659
nbalt	0.0124943
bnef	0.0114078
headw	0.0111362
divl	0.0103213
subl	0.00896328
blef	0.00842005
mull	0.00733359
shrl	0.00706197
bgeb	0.00706197
consm	0.00679036
modl	0.00651875
beqf	0.00597552
bgef	0.00597552
shll	0.00597552
bgel	0.0057039
bgec	0.0057039
addb	0.00543229
bnel	0.00543229
cvtcf	0.00516067
xorb	0.00516067
blec	0.00488906
bltl	0.00461744
cvtlc	0.00461744
negf	0.00434583
orl	0.00434583
cvtfl	0.00407422
cvtlf	0.00407422
shlb	0.0038026
beql	0.0038026
bleb	0.0038026
bgtl	0.00353099
cvtfc	0.00353099
bgtf	0.00353099
shrb	0.00325937
cvtcl	0.00298776
headm	0.00298776
blel	0.00244453
bgtb	0.00217292
andl	0.00217292
consb	0.00135807
consl	0.00135807
bltf	0.00135807
xorl	0.00135807
subb	0.00108646
headb	0.00108646
headl	0.00108646
bgtc	0.000814843
newcm	0.000814843
bltc	0.000543229
newcf	0.000271614