<s>
asm.js	B-Language
is	O
a	O
subset	O
of	O
JavaScript	B-Language
designed	O
to	O
allow	O
computer	B-Application
software	I-Application
written	O
in	O
languages	O
such	O
as	O
C	B-Language
to	O
be	O
run	O
as	O
web	B-Application
applications	I-Application
while	O
maintaining	O
performance	O
characteristics	O
considerably	O
better	O
than	O
standard	O
JavaScript	B-Language
,	O
which	O
is	O
the	O
typical	O
language	O
used	O
for	O
such	O
applications	O
.	O
</s>
<s>
asm.js	B-Language
consists	O
of	O
a	O
strict	O
subset	O
of	O
JavaScript	B-Language
,	O
to	O
which	O
code	O
written	O
in	O
statically-typed	O
languages	O
with	O
manual	O
memory	O
management	O
(	O
such	O
as	O
C	B-Language
)	O
is	O
translated	O
by	O
a	O
source-to-source	B-Language
compiler	I-Language
such	O
as	O
Emscripten	B-Language
(	O
based	O
on	O
LLVM	B-Application
)	O
.	O
</s>
<s>
Performance	O
is	O
improved	O
by	O
limiting	O
language	O
features	O
to	O
those	O
amenable	O
to	O
ahead-of-time	B-Application
optimization	I-Application
and	O
other	O
performance	O
improvements	O
.	O
</s>
<s>
Mozilla	B-Application
Firefox	I-Application
was	O
the	O
first	O
web	B-Application
browser	I-Application
to	O
implement	O
asm.js-specific	O
optimizations	O
,	O
starting	O
with	O
version	O
22	O
.	O
</s>
<s>
asm.js	B-Language
is	O
superseded	O
by	O
WebAssembly	B-Language
.	O
</s>
<s>
asm.js	B-Language
enables	O
significant	O
performance	O
improvements	O
for	O
web	B-Application
applications	I-Application
,	O
but	O
does	O
not	O
aim	O
to	O
improve	O
the	O
performance	O
of	O
hand-written	O
JavaScript	B-Language
code	O
,	O
nor	O
does	O
it	O
enable	O
anything	O
other	O
than	O
enhanced	O
performance	O
.	O
</s>
<s>
It	O
is	O
intended	O
to	O
have	O
performance	O
characteristics	O
closer	O
to	O
that	O
of	O
native	O
code	O
than	O
standard	O
JavaScript	B-Language
by	O
limiting	O
language	O
features	O
to	O
those	O
amenable	O
to	O
ahead-of-time	B-Application
optimization	I-Application
and	O
other	O
performance	O
improvements	O
.	O
</s>
<s>
By	O
using	O
a	O
subset	O
of	O
JavaScript	B-Language
,	O
asm.js	B-Language
is	O
largely	O
supported	O
by	O
all	O
major	O
web	B-Application
browsers	I-Application
,	O
unlike	O
alternative	O
approaches	O
such	O
as	O
Google	B-Application
Native	I-Application
Client	I-Application
.	O
</s>
<s>
asm.js	B-Language
is	O
not	O
typically	O
written	O
directly	O
:	O
instead	O
,	O
as	O
an	O
intermediate	O
language	O
,	O
it	O
is	O
generated	O
through	O
the	O
use	O
of	O
a	O
compiler	B-Language
that	O
takes	O
source	O
code	O
in	O
a	O
language	O
such	O
as	O
C++	B-Language
and	O
outputs	O
asm.js	B-Language
.	O
</s>
<s>
For	O
example	O
,	O
given	O
the	O
following	O
C	B-Language
code	O
:	O
</s>
<s>
Emscripten	B-Language
would	O
output	O
the	O
following	O
JS	O
code	O
:	O
</s>
<s>
In	O
JavaScript	B-Language
,	O
bitwise	O
operators	O
convert	O
their	O
operands	O
to	O
32-bit	O
signed	O
integers	O
and	O
give	O
integer	O
results	O
.	O
</s>
<s>
This	O
means	O
that	O
a	O
bitwise	O
OR	O
with	O
zero	O
converts	O
a	O
value	O
to	O
an	O
integer	O
(	O
a	O
very	O
simple	O
"	O
conceptual	O
"	O
presentation	O
of	O
bitwise	O
operators	O
may	O
not	O
deal	O
with	O
type	O
conversion	O
at	O
all	O
,	O
but	O
every	O
programming	O
language	O
defines	O
operators	O
for	O
its	O
own	O
convenience	O
,	O
as	O
Javascript	B-Language
does	O
here	O
)	O
.	O
</s>
<s>
These	O
conversions	O
are	O
required	O
by	O
asm.js	B-Language
,	O
so	O
that	O
an	O
optimising	O
compiler	B-Language
can	O
produce	O
highly	O
efficient	O
native	O
code	O
ahead-of-time	B-Application
.	O
</s>
<s>
In	O
such	O
an	O
optimising	O
compiler	B-Language
,	O
no	O
conversions	O
are	O
performed	O
when	O
asm.js	B-Language
code	O
calls	O
other	O
asm.js	B-Language
code	O
,	O
as	O
the	O
required	O
type	O
specifiers	O
mean	O
it	O
is	O
guaranteed	O
that	O
values	O
will	O
already	O
have	O
the	O
correct	O
type	O
.	O
</s>
<s>
This	O
would	O
result	O
in	O
the	O
following	O
asm.js	B-Language
code	O
:	O
</s>
<s>
In	O
the	O
generated	O
code	O
,	O
the	O
variable	O
MEM8	O
is	O
actually	O
a	O
byte-by-byte	O
"	O
view	O
"	O
of	O
a	O
typed	O
buffer	O
,	O
which	O
serves	O
as	O
the	O
"	O
heap	O
"	O
of	O
the	O
asm.js	B-Language
code	O
.	O
</s>
<s>
Since	O
asm.js	B-Language
runs	O
in	O
a	O
browser	B-Application
,	O
the	O
performance	O
heavily	O
depends	O
on	O
both	O
the	O
browser	B-Application
and	O
hardware	O
.	O
</s>
<s>
Preliminary	O
benchmarks	O
of	O
C	B-Language
programs	I-Language
compiled	B-Language
to	O
asm.js	B-Language
are	O
usually	O
within	O
a	O
factor	O
of	O
2	O
slower	O
than	O
native	O
compilation	B-Language
with	O
Clang	B-Application
.	O
</s>
<s>
Much	O
of	O
this	O
performance	O
gain	O
over	O
normal	O
JavaScript	B-Language
is	O
due	O
to	O
100%	O
type	O
consistency	O
and	O
virtually	O
no	O
garbage	B-General_Concept
collection	I-General_Concept
(	O
memory	O
is	O
manually	O
managed	O
in	O
a	O
large	O
typed	O
array	O
)	O
.	O
</s>
<s>
Mozilla	B-Operating_System
's	O
benchmark	O
from	O
December	O
2013	O
showed	O
significant	O
improvements	O
:	O
"	O
Firefox	B-Application
with	O
float32	O
optimizations	O
can	O
run	O
all	O
those	O
benchmarks	O
at	O
around	O
1.5	O
×	O
slower	O
than	O
native	O
,	O
or	O
better.	O
"	O
</s>
<s>
Mozilla	B-Operating_System
points	O
out	O
that	O
the	O
performance	O
of	O
natively	O
compiled	B-Language
code	O
is	O
not	O
a	O
single	O
measure	O
but	O
rather	O
a	O
range	O
,	O
with	O
different	O
native	O
compilers	B-Language
(	O
in	O
this	O
case	O
Clang	B-Application
and	O
GCC	B-Application
)	O
delivering	O
code	O
of	O
differing	O
performance	O
.	O
</s>
<s>
"	O
In	O
fact	O
,	O
on	O
some	O
benchmarks	O
,	O
like	O
Box2D	B-Application
,	O
FASTA	B-Application
and	O
copy	O
,	O
asm.js	B-Language
is	O
as	O
close	O
or	O
closer	O
to	O
Clang	B-Application
than	O
Clang	B-Application
is	O
to	O
GCC	B-Application
.	O
</s>
<s>
In	O
one	O
case	O
,	O
asm.js	B-Language
even	O
beats	O
Clang	B-Application
by	O
a	O
slight	O
amount	O
on	O
Box2D.	O
"	O
</s>
<s>
The	O
Emscripten	B-Language
project	O
provides	O
tools	O
that	O
can	O
be	O
used	O
to	O
compile	B-Language
C	B-Language
and	O
C++	B-Language
codebases	O
(	O
or	O
any	O
other	O
languages	O
that	O
can	O
be	O
converted	O
to	O
LLVM	B-Application
IR	B-Application
)	O
into	O
asm.js	B-Language
.	O
</s>
<s>
All	O
browsers	B-Application
with	O
support	O
for	O
ECMAScript	O
6	O
should	O
be	O
able	O
to	O
run	O
asm.js	B-Language
code	O
,	O
as	O
it	O
is	O
a	O
subset	O
of	O
that	O
specification	O
.	O
</s>
<s>
However	O
,	O
since	O
features	O
were	O
added	O
in	O
that	O
edition	O
to	O
enable	O
full	O
asm.js	B-Language
support	O
(	O
)	O
,	O
older	O
browsers	B-Application
lacking	O
those	O
features	O
may	O
encounter	O
problems	O
.	O
</s>
<s>
Some	O
browser	B-Application
implementations	O
are	O
especially	O
optimised	O
for	O
asm.js	B-Language
:	O
</s>
<s>
Mozilla	B-Application
Firefox	I-Application
was	O
the	O
first	O
web	B-Application
browser	I-Application
to	O
implement	O
asm.js-specific	O
optimizations	O
,	O
starting	O
with	O
Firefox	B-Application
22	O
.	O
</s>
<s>
OdinMonkey	O
,	O
Mozilla	B-Operating_System
's	O
asm.js	B-Language
ahead-of-time	B-Application
compiler	I-Application
used	O
in	O
Firefox	B-Application
,	O
is	O
a	O
component	O
of	O
IonMonkey	O
,	O
the	O
JIT	O
compiler	B-Language
of	O
SpiderMonkey	B-Language
.	O
</s>
<s>
Microsoft	O
was	O
implementing	O
support	O
for	O
asm.js	B-Language
in	O
Chakra	B-Language
,	O
the	O
JavaScript	B-Language
engine	O
used	O
by	O
Microsoft	B-Application
Edge	I-Application
Legacy	I-Application
,	O
performing	O
validation	O
to	O
produce	O
highly	O
optimised	O
JIT	O
code	O
.	O
</s>
<s>
The	O
optimizations	O
of	O
Google	B-Application
Chrome	I-Application
's	O
V8	B-Language
JavaScript	I-Language
engine	I-Language
in	O
Chrome	B-Application
28	O
made	O
asm.js	B-Language
benchmarks	O
more	O
than	O
twice	O
as	O
fast	O
as	O
prior	O
versions	O
of	O
Chrome	B-Application
,	O
although	O
Chrome	B-Application
's	O
V8	B-Language
does	O
not	O
use	O
ahead-of-time	B-Application
compilation	I-Application
.	O
</s>
<s>
Almost	O
all	O
of	O
the	O
current	O
applications	O
based	O
on	O
asm.js	B-Language
are	O
C/C	B-Language
++	I-Language
applications	O
compiled	B-Language
to	O
asm.js	B-Language
using	O
Emscripten	B-Language
or	O
Mandreel	O
.	O
</s>
<s>
With	O
that	O
in	O
mind	O
,	O
the	O
kind	O
of	O
applications	O
that	O
are	O
going	O
to	O
target	O
asm.js	B-Language
in	O
the	O
near	O
future	O
are	O
those	O
that	O
will	O
benefit	O
from	O
the	O
portability	O
of	O
running	O
in	O
a	O
browser	B-Application
but	O
which	O
have	O
a	O
level	O
of	O
complexity	O
for	O
which	O
a	O
direct	O
port	O
to	O
JavaScript	B-Language
would	O
be	O
infeasible	O
.	O
</s>
<s>
So	O
far	O
,	O
a	O
number	O
of	O
programming	O
languages	O
,	O
application	B-Application
frameworks	I-Application
,	O
programs	B-Application
,	O
libraries	B-Library
,	O
games	O
,	O
game	O
engines	O
and	O
other	O
software	O
have	O
already	O
been	O
ported	O
.	O
</s>
<s>
Every	O
game	O
in	O
the	O
Humble	O
Mozilla	B-Operating_System
Bundle	O
(	O
Super	B-Application
Hexagon	I-Application
,	O
AaAaAA	O
!	O
</s>
<s>
HTML5	O
Fractal	B-Application
Playground	O
–	O
draws	O
iterating-function	O
generated	O
fractals	B-Application
,	O
such	O
as	O
the	B-Algorithm
Mandelbrot	I-Algorithm
set	I-Algorithm
.	O
</s>
<s>
asm.js	B-Language
is	O
mostly	O
rendered	O
obsolete	O
with	O
the	O
introduction	O
of	O
WebAssembly	B-Language
(	O
wasm	O
)	O
,	O
which	O
has	O
a	O
bytecode	O
format	O
that	O
is	O
faster	O
to	O
parse	O
.	O
</s>
<s>
Efforts	O
to	O
extend	O
JavaScript	B-Language
with	O
more	O
low-level	O
features	O
like	O
SIMD.js	O
has	O
also	O
been	O
suspended	O
since	O
2017	O
.	O
</s>
<s>
asm.js	B-Language
remains	O
useful	O
primarily	O
as	O
a	O
"	O
fallback	O
"	O
for	O
wasm	O
,	O
through	O
a	O
program	O
written	O
by	O
the	O
WebAssembly	B-Language
organization	O
that	O
converts	O
wasm	O
to	O
asm.js	B-Language
.	O
</s>
<s>
There	O
is	O
no	O
dedicated	O
converter	O
from	O
asm.js	B-Language
to	O
wasm	O
,	O
but	O
TypeScript-to-wasm	O
compilers	B-Language
can	O
be	O
partially	O
used	O
.	O
</s>
<s>
The	O
reference	O
WebAssembly	B-Language
emitter	O
binaryen	O
used	O
to	O
contain	O
an	O
module	O
,	O
but	O
it	O
was	O
removed	O
after	O
Emscripten	B-Language
stopped	O
using	O
it	O
.	O
</s>
