[解决]编译 webkitgtk-2.18.6 有个奇怪的问题。是架构的特殊问题,还是 python 的浮点计算出错?

解决,gcc 的 rpm 在 configure 时增加了 --with-madd4=no 。
在重新编译 glibc ,之后重编译 python2 就好了。
==========
请注意,有些内容被吞了,比如
print ".16f"%memoryBits
其实应该是
print "%16.16f"%memoryBits
第一个百分号,替换成了汉字全角才现实。
-------------------------------------------
--- webkitgtk-2.18.6-orig/Source/JavaScriptCore/wasm/generateWasm.py    2018-03-03 19:01:28.441007606 +0800
+++ webkitgtk-2.18.6/Source/JavaScriptCore/wasm/generateWasm.py 2018-03-03 19:03:56.015243319 +0800
@@ -101,5 +101,5 @@
assert op["opcode"]["category"] == "memory"
match = re.match(r'^[if]([36][24])\.[^0-9]+([0-9]+)?_?[us]?$', op["name"])
memoryBits = int(match.group(2) if match.group(2) else match.group(1))
- assert 2 ** math.log(memoryBits, 2) == memoryBits
+ assert 2 ** int(math.log(memoryBits, 2)) == memoryBits
return str(int(math.log(memoryBits / 8, 2)))






这个 patch 这么打就可以编译过,不然 assert 这里 == 的前面不是一个整数,导致前后不相等而报错退出。

把这里修改一下,输出这些数据:
def memoryLog2Alignment(op):
assert op["opcode"]["category"] == "memory"
match = re.match(r'^[if]([36][24])\.[^0-9]+([0-9]+)?_?[us]?$', op["name"])
memoryBits = int(match.group(2) if match.group(2) else match.group(1))
print "data:"
print memoryBits
print math.log(memoryBits, 2)
print 2 ** math.log(memoryBits, 2)
print "-----"
assert 2 ** math.log(memoryBits, 2) == memoryBits
return str(int(math.log(memoryBits / 8, 2)))
输出如下。也就是说,其实两个数一样,顶多一个是整数,一个是浮点。但是就是不相等?
cd /builddir/build/BUILD/webkitgtk-2.18.6/mips64el-redhat-linux-gnu/Source/JavaScriptCore && /usr/bin/python2.7 /builddir/build/BUILD/webkitgtk-2.18.6/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py /builddir/build/BUILD/webkitgtk-2.18.6/Source/JavaScriptCore/wasm/wasm.json /builddir/build/BUILD/webkitgtk-2.18.6/mips64el-redhat-linux-gnu/DerivedSources/JavaScriptCore/WasmOps.h
data:
32
5.0
32.0
-----
data:
32
5.0
32.0
-----
data:
16
4.0
16.0
-----
data:
16
4.0
16.0
-----
data:
64
6.0
64.0
-----
Traceback (most recent call last):
File "/builddir/build/BUILD/webkitgtk-2.18.6/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py", line 115, in <module>
memoryLog2AlignmentLoads = memoryLog2AlignmentGenerator(lambda op: (op["category"] == "memory" and len(op["return"]) == 1))
File "/builddir/build/BUILD/webkitgtk-2.18.6/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py", line 112, in memoryLog2AlignmentGenerator
result.append(" case " + wasm.toCpp(op["name"]) + ": return " + memoryLog2Alignment(op) + ";")
File "/builddir/build/BUILD/webkitgtk-2.18.6/Source/JavaScriptCore/wasm/generateWasm.py", line 109, in memoryLog2Alignment
assert 2 ** math.log(memoryBits, 2) == memoryBits
AssertionError






设定输出为浮点数:
def memoryLog2Alignment(op):
assert op["opcode"]["category"] == "memory"
match = re.match(r'^[if]([36][24])\.[^0-9]+([0-9]+)?_?[us]?$', op["name"])
memoryBits = int(match.group(2) if match.group(2) else match.group(1))
print "data:"
print ".16f"%memoryBits
print ".16f"%math.log(memoryBits, 2)
print ".16f"%(2 ** math.log(memoryBits, 2))
print "-----"
assert 2 ** math.log(memoryBits, 2) == memoryBits
return str(int(math.log(memoryBits / 8, 2)))
终于暴露目标了
cd /builddir/build/BUILD/webkitgtk-2.18.6/mips64el-redhat-linux-gnu/Source/JavaScriptCore && /usr/bin/python2.7 /builddir/build/BUILD/webkitgtk-2.18.6/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py /builddir/build/BUILD/webkitgtk-2.18.6/Source/JavaScriptCore/wasm/wasm.json /builddir/build/BUILD/webkitgtk-2.18.6/mips64el-redhat-linux-gnu/DerivedSources/JavaScriptCore/WasmOps.h
data:
32.0000000000000000
5.0000000000000000
32.0000000000000000
-----
data:
32.0000000000000000
5.0000000000000000
32.0000000000000000
-----
data:
16.0000000000000000
4.0000000000000000
16.0000000000000000
-----
data:
16.0000000000000000
4.0000000000000000
16.0000000000000000
-----
data:
64.0000000000000000
6.0000000000000000
63.9999999999999858
-----
Traceback (most recent call last):
File "/builddir/build/BUILD/webkitgtk-2.18.6/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py", line 115, in <module>
memoryLog2AlignmentLoads = memoryLog2AlignmentGenerator(lambda op: (op["category"] == "memory" and len(op["return"]) == 1))
File "/builddir/build/BUILD/webkitgtk-2.18.6/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py", line 112, in memoryLog2AlignmentGenerator
result.append(" case " + wasm.toCpp(op["name"]) + ": return " + memoryLog2Alignment(op) + ";")
File "/builddir/build/BUILD/webkitgtk-2.18.6/Source/JavaScriptCore/wasm/generateWasm.py", line 109, in memoryLog2Alignment
assert 2 ** math.log(memoryBits, 2) == memoryBits
AssertionError




浮点计算错!
已邀请:

jiangtao9999

赞同来自: Holoo xen0n

也就是说计算次方,如果使用的数字是浮点数而不是整数,就会出现偏差?!
[jiangtao@ls3a_fc27 srpm]$ python2
Python 2.7.14 (default, Feb 14 2018, 19:33:26)
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> print ".16f"%math.log(64,2)
6.0000000000000000
>>> print ".16f"%(2**math.log(64,2))
63.9999999999999858
>>> print ".16f"%(2**6)
64.0000000000000000
>>> print ".16f"%(2**6.00000000000)
63.9999999999999858
>>> exit()
[jiangtao@ls3a_fc27 srpm]$
[jiangtao@ls3a_fc27 srpm]$ python2
Python 2.7.14 (default, Feb 14 2018, 19:33:26)
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> print ".16f"%(2**6)
64.0000000000000000
>>> print ".16f"%(2**6.0)
63.9999999999999858
>>> exit()
[jiangtao@ls3a_fc27 srpm]$



x86 的 fedora 上面,没出现这个问题。

xuchenghua

赞同来自: zzz19760225

正确使用融合浮点乘加指令要确保以下三点:
一、编译器修改,参见http://www.loongnix.org/cgit/gcc-4.9.3/commit/?id=954756b1968fed8426f0f0d2676603289936d5f7,该patch在gcc7中已经合入主分支。
二、glibc中要加入patch。http://www.loongnix.org/cgit/glibc-2.20/commit/?id=14023742e6ef571b61439d0d7bb7939e663fe624
三、内核中也要加入相应patch。http://www.loongnix.org/cgit/linux-3.10/commit/?id=0b73186a37c6cf3a6ef5e3dfd84ce2038592ad60
 

xen0n

赞同来自:

https://github.com/rust-lang/rust/issues/39013#issuecomment-272442396
 
Rust 的 Debian MIPS port 也碰到类似问题,不知道是不是同一个?据说龙芯 FPU 有坑。。。。。感觉堪比 Intel 当年的 fdiv bug,希望新的龙芯硬件别坑!

xuchenghua

赞同来自:

1、我没有细追你的问题到底是什么引起的,是否在loongnix1.0上也存在?
2、参考https://patchwork.ozlabs.org/patch/707930/#1540803 中的c#8。

jiangtao9999

赞同来自:

目前确认,fedora 28 的 gcc8 + glibc 2.27 并没有修复,还是需要给 gcc 加参数。

要回复问题请先登录注册