<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[189984] trunk/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/189984">189984</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-09-18 14:29:54 -0700 (Fri, 18 Sep 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Implement type conversion instructions in WebAssembly
https://bugs.webkit.org/show_bug.cgi?id=149340

Patch by Sukolsak Sakshuwong &lt;sukolsak@gmail.com&gt; on 2015-09-18
Reviewed by Mark Lam.

This patch implements some type conversion instructions in WebAssembly.
The WebAssembly spec has a lot more type conversion instructions than
what are available in asm.js.[1] We only implement the ones that are in
asm.js for now because we can only test those.

[1]: https://github.com/WebAssembly/design/blob/master/AstSemantics.md

* tests/stress/wasm-type-conversion.js:
* tests/stress/wasm/type-conversion.wasm:
* wasm/WASMConstants.h:
* wasm/WASMFunctionCompiler.h:
(JSC::operationConvertUnsignedInt32ToDouble):
(JSC::WASMFunctionCompiler::buildConvertType):
(JSC::WASMFunctionCompiler::callOperation):
* wasm/WASMFunctionParser.cpp:
(JSC::WASMFunctionParser::parseExpressionI32):
(JSC::WASMFunctionParser::parseExpressionF32):
(JSC::WASMFunctionParser::parseExpressionF64):
(JSC::WASMFunctionParser::parseConvertType):
* wasm/WASMFunctionParser.h:
* wasm/WASMFunctionSyntaxChecker.h:
(JSC::WASMFunctionSyntaxChecker::buildConvertType):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstresswasmtypeconversionwasm">trunk/Source/JavaScriptCore/tests/stress/wasm/type-conversion.wasm</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstresswasmtypeconversionjs">trunk/Source/JavaScriptCore/tests/stress/wasm-type-conversion.js</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMConstantsh">trunk/Source/JavaScriptCore/wasm/WASMConstants.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionCompilerh">trunk/Source/JavaScriptCore/wasm/WASMFunctionCompiler.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionParsercpp">trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionParserh">trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionSyntaxCheckerh">trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (189983 => 189984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-09-18 21:08:02 UTC (rev 189983)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-09-18 21:29:54 UTC (rev 189984)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2015-09-18  Sukolsak Sakshuwong  &lt;sukolsak@gmail.com&gt;
+
+        Implement type conversion instructions in WebAssembly
+        https://bugs.webkit.org/show_bug.cgi?id=149340
+
+        Reviewed by Mark Lam.
+
+        This patch implements some type conversion instructions in WebAssembly.
+        The WebAssembly spec has a lot more type conversion instructions than
+        what are available in asm.js.[1] We only implement the ones that are in
+        asm.js for now because we can only test those.
+
+        [1]: https://github.com/WebAssembly/design/blob/master/AstSemantics.md
+
+        * tests/stress/wasm-type-conversion.js:
+        * tests/stress/wasm/type-conversion.wasm:
+        * wasm/WASMConstants.h:
+        * wasm/WASMFunctionCompiler.h:
+        (JSC::operationConvertUnsignedInt32ToDouble):
+        (JSC::WASMFunctionCompiler::buildConvertType):
+        (JSC::WASMFunctionCompiler::callOperation):
+        * wasm/WASMFunctionParser.cpp:
+        (JSC::WASMFunctionParser::parseExpressionI32):
+        (JSC::WASMFunctionParser::parseExpressionF32):
+        (JSC::WASMFunctionParser::parseExpressionF64):
+        (JSC::WASMFunctionParser::parseConvertType):
+        * wasm/WASMFunctionParser.h:
+        * wasm/WASMFunctionSyntaxChecker.h:
+        (JSC::WASMFunctionSyntaxChecker::buildConvertType):
+
</ins><span class="cx"> 2015-09-18  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Fix tests on Windows after switching to CMake.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstresswasmtypeconversionwasm"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tests/stress/wasm/type-conversion.wasm (189983 => 189984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/wasm/type-conversion.wasm        2015-09-18 21:08:02 UTC (rev 189983)
+++ trunk/Source/JavaScriptCore/tests/stress/wasm/type-conversion.wasm        2015-09-18 21:29:54 UTC (rev 189984)
</span><span class="lines">@@ -1,4 +1,11 @@
</span><del>-wasm\xEFgetInt32getDoublegetStringgetBoolean-\x80\xC0\x80\xA0\x80\xA0\x80\x80\x80\x80\x80 \x80 \x80 \x80 \x80\xA0\x80
- \xA0 takeAndReturnInt32takeAndReturnFloattakeAndReturnDoublereturnInt32FromInt32returnInt32FromDoublereturnInt32FromStringreturnInt32FromBooleanreturnDoubleFromInt32returnDoubleFromDoublereturnDoubleFromString        returnDoubleFromBoolean
-add
</del><span class="cx">\ No newline at end of file
</span><ins>+wasm\x9C getInt32        
+getDouble        
+getString        
+getBoolean        
+                                
+
+
+
+\x80\xC0\x80\xC0\x80\xC0\x80\xC0\x80\xA0\x80\xA0\x80\xA0\x80\xA0\x80\xC0\x80\xA0\x80\xA0\x80\x80\x80\x80\x80 \x80 \x80 \x80 convertIntToFloatconvertUnsignedIntToFloatconvertIntToDoubleconvertUnsignedIntToDoubleconvertFloatToIntconvertFloatToDoubleconvertDoubleToIntconvertDoubleToFloattakeAndReturnInt32takeAndReturnFloat        takeAndReturnDouble
+returnInt32FromInt32 returnInt32FromDouble returnInt32FromString+returnInt32FromBooleanreturnDoubleFromInt32returnDoubleFromDoublereturnDoubleFromStringreturnDoubleFromBoolean
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstresswasmtypeconversionjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tests/stress/wasm-type-conversion.js (189983 => 189984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/wasm-type-conversion.js        2015-09-18 21:08:02 UTC (rev 189983)
+++ trunk/Source/JavaScriptCore/tests/stress/wasm-type-conversion.js        2015-09-18 21:29:54 UTC (rev 189984)
</span><span class="lines">@@ -17,6 +17,46 @@
</span><span class="cx">     var getString = imports.getString;
</span><span class="cx">     var getBoolean = imports.getBoolean;
</span><span class="cx"> 
</span><ins>+    function convertIntToFloat(x) {
+        x = x | 0;
+        return fround(x | 0);
+    }
+
+    function convertUnsignedIntToFloat(x) {
+        x = x | 0;
+        return fround(x &gt;&gt;&gt; 0);
+    }
+
+    function convertIntToDouble(x) {
+        x = x | 0;
+        return +(x | 0);
+    }
+
+    function convertUnsignedIntToDouble(x) {
+        x = x | 0;
+        return +(x &gt;&gt;&gt; 0);
+    }
+
+    function convertFloatToInt(x) {
+        x = fround(x);
+        return ~~x;
+    }
+
+    function convertFloatToDouble(x) {
+        x = fround(x);
+        return +x;
+    }
+
+    function convertDoubleToInt(x) {
+        x = +x;
+        return ~~x;
+    }
+
+    function convertDoubleToFloat(x) {
+        x = +x;
+        return fround(x);
+    }
+
</ins><span class="cx">     function takeAndReturnInt32(x) {
</span><span class="cx">         x = x | 0;
</span><span class="cx">         return x | 0;
</span><span class="lines">@@ -65,6 +105,15 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return {
</span><ins>+        convertIntToFloat: convertIntToFloat,
+        convertUnsignedIntToFloat: convertUnsignedIntToFloat,
+        convertIntToDouble: convertIntToDouble,
+        convertUnsignedIntToDouble: convertUnsignedIntToDouble,
+        convertFloatToInt: convertFloatToInt,
+        convertFloatToDouble: convertFloatToDouble,
+        convertDoubleToInt: convertDoubleToInt,
+        convertDoubleToFloat: convertDoubleToFloat,
+
</ins><span class="cx">         takeAndReturnInt32: takeAndReturnInt32,
</span><span class="cx">         takeAndReturnFloat: takeAndReturnFloat,
</span><span class="cx">         takeAndReturnDouble: takeAndReturnDouble,
</span><span class="lines">@@ -89,6 +138,15 @@
</span><span class="cx"> };
</span><span class="cx"> var module = loadWebAssembly(&quot;wasm/type-conversion.wasm&quot;, imports);
</span><span class="cx"> 
</span><ins>+shouldBe(module.convertIntToFloat(-1), -1);
+shouldBe(module.convertUnsignedIntToFloat(-1), 4294967296);
+shouldBe(module.convertIntToDouble(-1), -1);
+shouldBe(module.convertUnsignedIntToDouble(-1), 4294967295);
+shouldBe(module.convertFloatToInt(4.2), 4);
+shouldBe(module.convertFloatToDouble(4.2), 4.199999809265137);
+shouldBe(module.convertDoubleToInt(4.2), 4);
+shouldBe(module.convertDoubleToFloat(4.2), 4.199999809265137);
+
</ins><span class="cx"> var two = {
</span><span class="cx">     valueOf() { return 2; }
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMConstantsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMConstants.h (189983 => 189984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMConstants.h        2015-09-18 21:08:02 UTC (rev 189983)
+++ trunk/Source/JavaScriptCore/wasm/WASMConstants.h        2015-09-18 21:29:54 UTC (rev 189984)
</span><span class="lines">@@ -284,6 +284,13 @@
</span><span class="cx">     NumberOfExportFormats
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+enum class WASMTypeConversion {
+    ConvertSigned,
+    ConvertUnsigned,
+    Promote,
+    Demote,
+};
+
</ins><span class="cx"> static const uint8_t hasImmediateInOpFlag = 0x80;
</span><span class="cx"> 
</span><span class="cx"> static const unsigned opWithImmediateBits = 2;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionCompilerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMFunctionCompiler.h (189983 => 189984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionCompiler.h        2015-09-18 21:08:02 UTC (rev 189983)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionCompiler.h        2015-09-18 21:29:54 UTC (rev 189984)
</span><span class="lines">@@ -71,6 +71,13 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if !USE(JSVALUE64)
+static double JIT_OPERATION operationConvertUnsignedInt32ToDouble(uint32_t value)
+{
+    return static_cast&lt;double&gt;(value);
+}
+#endif
+
</ins><span class="cx"> class WASMFunctionCompiler : private CCallHelpers {
</span><span class="cx"> public:
</span><span class="cx">     typedef int Expression;
</span><span class="lines">@@ -368,6 +375,67 @@
</span><span class="cx">         return UNUSED;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    int buildConvertType(int, WASMExpressionType fromType, WASMExpressionType toType, WASMTypeConversion conversion)
+    {
+        switch (fromType) {
+        case WASMExpressionType::I32:
+            load32(temporaryAddress(m_tempStackTop - 1), GPRInfo::regT0);
+            ASSERT(toType == WASMExpressionType::F32 || toType == WASMExpressionType::F64);
+            if (conversion == WASMTypeConversion::ConvertSigned)
+                convertInt32ToDouble(GPRInfo::regT0, FPRInfo::fpRegT0);
+            else {
+                ASSERT(conversion == WASMTypeConversion::ConvertUnsigned);
+#if USE(JSVALUE64)
+                convertInt64ToDouble(GPRInfo::regT0, FPRInfo::fpRegT0);
+#else
+                callOperation(operationConvertUnsignedInt32ToDouble, GPRInfo::regT0, FPRInfo::fpRegT0);
+#endif
+            }
+            if (toType == WASMExpressionType::F32)
+                convertDoubleToFloat(FPRInfo::fpRegT0, FPRInfo::fpRegT0);
+            storeDouble(FPRInfo::fpRegT0, temporaryAddress(m_tempStackTop - 1));
+            break;
+        case WASMExpressionType::F32:
+            loadDouble(temporaryAddress(m_tempStackTop - 1), FPRInfo::fpRegT0);
+            switch (toType) {
+            case WASMExpressionType::I32:
+                ASSERT(conversion == WASMTypeConversion::ConvertSigned);
+                convertFloatToDouble(FPRInfo::fpRegT0, FPRInfo::fpRegT0);
+                truncateDoubleToInt32(FPRInfo::fpRegT0, GPRInfo::regT0);
+                store32(GPRInfo::regT0, temporaryAddress(m_tempStackTop - 1));
+                break;
+            case WASMExpressionType::F64:
+                ASSERT(conversion == WASMTypeConversion::Promote);
+                convertFloatToDouble(FPRInfo::fpRegT0, FPRInfo::fpRegT0);
+                storeDouble(FPRInfo::fpRegT0, temporaryAddress(m_tempStackTop - 1));
+                break;
+            default:
+                ASSERT_NOT_REACHED();
+            }
+            break;
+        case WASMExpressionType::F64:
+            loadDouble(temporaryAddress(m_tempStackTop - 1), FPRInfo::fpRegT0);
+            switch (toType) {
+            case WASMExpressionType::I32:
+                ASSERT(conversion == WASMTypeConversion::ConvertSigned);
+                truncateDoubleToInt32(FPRInfo::fpRegT0, GPRInfo::regT0);
+                store32(GPRInfo::regT0, temporaryAddress(m_tempStackTop - 1));
+                break;
+            case WASMExpressionType::F32:
+                ASSERT(conversion == WASMTypeConversion::Demote);
+                convertDoubleToFloat(FPRInfo::fpRegT0, FPRInfo::fpRegT0);
+                storeDouble(FPRInfo::fpRegT0, temporaryAddress(m_tempStackTop - 1));
+                break;
+            default:
+                ASSERT_NOT_REACHED();
+            }
+            break;
+        default:
+            ASSERT_NOT_REACHED();
+        }
+        return UNUSED;
+    }
+
</ins><span class="cx">     int buildUnaryI32(int, WASMOpExpressionI32 op)
</span><span class="cx">     {
</span><span class="cx">         load32(temporaryAddress(m_tempStackTop - 1), GPRInfo::regT0);
</span><span class="lines">@@ -929,6 +997,12 @@
</span><span class="cx">         appendCallSetResult(operation, dst);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    void callOperation(double JIT_OPERATION (*operation)(uint32_t), GPRReg src, FPRegisterID dst)
+    {
+        setupArguments(src);
+        appendCallSetResult(operation, dst, FloatingPointPrecision::Double);
+    }
+
</ins><span class="cx">     void boxArgumentsAndAdjustStackPointer(const Vector&lt;WASMType&gt;&amp; arguments)
</span><span class="cx">     {
</span><span class="cx">         size_t argumentCount = arguments.size();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp (189983 => 189984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp        2015-09-18 21:08:02 UTC (rev 189983)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp        2015-09-18 21:29:54 UTC (rev 189984)
</span><span class="lines">@@ -534,6 +534,10 @@
</span><span class="cx">             return parseCallIndirect(context, WASMExpressionType::I32);
</span><span class="cx">         case WASMOpExpressionI32::CallImport:
</span><span class="cx">             return parseCallImport(context, WASMExpressionType::I32);
</span><ins>+        case WASMOpExpressionI32::FromF32:
+            return parseConvertType(context, WASMExpressionType::F32, WASMExpressionType::I32, WASMTypeConversion::ConvertSigned);
+        case WASMOpExpressionI32::FromF64:
+            return parseConvertType(context, WASMExpressionType::F64, WASMExpressionType::I32, WASMTypeConversion::ConvertSigned);
</ins><span class="cx">         case WASMOpExpressionI32::Negate:
</span><span class="cx">         case WASMOpExpressionI32::BitNot:
</span><span class="cx">         case WASMOpExpressionI32::CountLeadingZeros:
</span><span class="lines">@@ -599,8 +603,6 @@
</span><span class="cx">         case WASMOpExpressionI32::StoreWithOffset32:
</span><span class="cx">         case WASMOpExpressionI32::Conditional:
</span><span class="cx">         case WASMOpExpressionI32::Comma:
</span><del>-        case WASMOpExpressionI32::FromF32:
-        case WASMOpExpressionI32::FromF64:
</del><span class="cx">         case WASMOpExpressionI32::SMin:
</span><span class="cx">         case WASMOpExpressionI32::UMin:
</span><span class="cx">         case WASMOpExpressionI32::SMax:
</span><span class="lines">@@ -750,6 +752,12 @@
</span><span class="cx">             return parseCallInternal(context, WASMExpressionType::F32);
</span><span class="cx">         case WASMOpExpressionF32::CallIndirect:
</span><span class="cx">             return parseCallIndirect(context, WASMExpressionType::F32);
</span><ins>+        case WASMOpExpressionF32::FromS32:
+            return parseConvertType(context, WASMExpressionType::I32, WASMExpressionType::F32, WASMTypeConversion::ConvertSigned);
+        case WASMOpExpressionF32::FromU32:
+            return parseConvertType(context, WASMExpressionType::I32, WASMExpressionType::F32, WASMTypeConversion::ConvertUnsigned);
+        case WASMOpExpressionF32::FromF64:
+            return parseConvertType(context, WASMExpressionType::F64, WASMExpressionType::F32, WASMTypeConversion::Demote);
</ins><span class="cx">         case WASMOpExpressionF32::Negate:
</span><span class="cx">         case WASMOpExpressionF32::Abs:
</span><span class="cx">         case WASMOpExpressionF32::Ceil:
</span><span class="lines">@@ -769,9 +777,6 @@
</span><span class="cx">         case WASMOpExpressionF32::StoreWithOffset:
</span><span class="cx">         case WASMOpExpressionF32::Conditional:
</span><span class="cx">         case WASMOpExpressionF32::Comma:
</span><del>-        case WASMOpExpressionF32::FromS32:
-        case WASMOpExpressionF32::FromU32:
-        case WASMOpExpressionF32::FromF64:
</del><span class="cx">             // FIXME: Implement these instructions.
</span><span class="cx">             FAIL_WITH_MESSAGE(&quot;Unsupported instruction.&quot;);
</span><span class="cx">         default:
</span><span class="lines">@@ -881,6 +886,12 @@
</span><span class="cx">             return parseCallImport(context, WASMExpressionType::F64);
</span><span class="cx">         case WASMOpExpressionF64::CallIndirect:
</span><span class="cx">             return parseCallIndirect(context, WASMExpressionType::F64);
</span><ins>+        case WASMOpExpressionF64::FromS32:
+            return parseConvertType(context, WASMExpressionType::I32, WASMExpressionType::F64, WASMTypeConversion::ConvertSigned);
+        case WASMOpExpressionF64::FromU32:
+            return parseConvertType(context, WASMExpressionType::I32, WASMExpressionType::F64, WASMTypeConversion::ConvertUnsigned);
+        case WASMOpExpressionF64::FromF32:
+            return parseConvertType(context, WASMExpressionType::F32, WASMExpressionType::F64, WASMTypeConversion::Promote);
</ins><span class="cx">         case WASMOpExpressionF64::SetLocal:
</span><span class="cx">         case WASMOpExpressionF64::SetGlobal:
</span><span class="cx">         case WASMOpExpressionF64::Load:
</span><span class="lines">@@ -889,9 +900,6 @@
</span><span class="cx">         case WASMOpExpressionF64::StoreWithOffset:
</span><span class="cx">         case WASMOpExpressionF64::Conditional:
</span><span class="cx">         case WASMOpExpressionF64::Comma:
</span><del>-        case WASMOpExpressionF64::FromS32:
-        case WASMOpExpressionF64::FromU32:
-        case WASMOpExpressionF64::FromF32:
</del><span class="cx">         case WASMOpExpressionF64::Negate:
</span><span class="cx">         case WASMOpExpressionF64::Add:
</span><span class="cx">         case WASMOpExpressionF64::Sub:
</span><span class="lines">@@ -1040,6 +1048,15 @@
</span><span class="cx">     return context.buildCallImport(functionImportSignature.functionImportIndex, argumentList, signature, returnType);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+template &lt;class Context&gt;
+ContextExpression WASMFunctionParser::parseConvertType(Context&amp; context, WASMExpressionType fromType, WASMExpressionType toType, WASMTypeConversion conversion)
+{
+    ContextExpression expression = parseExpression(context, fromType);
+    PROPAGATE_ERROR();
+
+    return context.buildConvertType(expression, fromType, toType, conversion);
+}
+
</ins><span class="cx"> } // namespace JSC
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(WEBASSEMBLY)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h (189983 => 189984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h        2015-09-18 21:08:02 UTC (rev 189983)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h        2015-09-18 21:29:54 UTC (rev 189984)
</span><span class="lines">@@ -117,6 +117,7 @@
</span><span class="cx">     template &lt;class Context&gt; ContextExpression parseCallInternal(Context&amp;, WASMExpressionType returnType);
</span><span class="cx">     template &lt;class Context&gt; ContextExpression parseCallIndirect(Context&amp;, WASMExpressionType returnType);
</span><span class="cx">     template &lt;class Context&gt; ContextExpression parseCallImport(Context&amp;, WASMExpressionType returnType);
</span><ins>+    template &lt;class Context&gt; ContextExpression parseConvertType(Context&amp;, WASMExpressionType fromType, WASMExpressionType toType, WASMTypeConversion);
</ins><span class="cx"> 
</span><span class="cx">     JSWASMModule* m_module;
</span><span class="cx">     WASMReader m_reader;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionSyntaxCheckerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h (189983 => 189984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h        2015-09-18 21:08:02 UTC (rev 189983)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h        2015-09-18 21:29:54 UTC (rev 189984)
</span><span class="lines">@@ -101,6 +101,11 @@
</span><span class="cx">         return UNUSED;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    int buildConvertType(int, WASMExpressionType, WASMExpressionType, WASMTypeConversion)
+    {
+        return UNUSED;
+    }
+
</ins><span class="cx">     int buildUnaryI32(int, WASMOpExpressionI32)
</span><span class="cx">     {
</span><span class="cx">         return UNUSED;
</span></span></pre>
</div>
</div>

</body>
</html>