我想编译一个Mathematica模块,因为我追求速度.
testC = Compile[{{inputInt, _Integer}},
Module[{outputInt, bitShift = 5},
outputInt = BitShiftRight[inputInt, bitShift]
]
, CompilationTarget -> "C", RuntimeOptions -> "Speed"
, CompilationOptions -> {"ExpressionOptimization" -> True,
"InlineCompiledFunctions" -> True,
"InlineExternalDefinitions" -> True}
];
Run Code Online (Sandbox Code Playgroud)
我的实际功能更长,但结构非常简单,使用列表,只包含以下功能:Total,Table,BitAnd,If.所有编译和运行时选项在我的实际函数中都很有用(可能),而不是这一行提取.
我已经设定
SetSystemOptions ["CompileOptions" - >"CompileReportExternal" - > True];
确保我能看到发生了什么,并且
CompilePrint [TESTC]
给出以下结果
1 argument
3 Integer registers
Underflow checking off
Overflow checking off
Integer overflow checking off
RuntimeAttributes -> {}
I0 = A1
I1 = 5
Result = I2
1 I2 = MainEvaluate[ Hold[BitShiftRight][ I0, …Run Code Online (Sandbox Code Playgroud)