我试图编译Zend引擎的这个溢出检测宏:
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
long __tmpvar; \
__asm__( \
"mul %0, %2, %3\n" \
"smulh %1, %2, %3\n" \
"sub %1, %1, %0, asr #63\n" \
: "=X"(__tmpvar), "=X"(usedval) \
: "X"(a), "X"(b)); \
if (usedval) (dval) = (double) (a) * (double) (b); \
else (lval) = __tmpvar; \
} while (0)
Run Code Online (Sandbox Code Playgroud)
并在装配中得到了这个结果:
; InlineAsm Start
mul x8, x8, x9
smulh x9, x8, x9
sub x9, x9, x8, asr #63
; InlineAsm End
Run Code Online (Sandbox Code Playgroud)
编译器仅对宏的输入和输出使用2个寄存器,我认为它必须至少为3,并导致错误的计算结果(例如,-1*-1).有什么建议吗?
我正在开发一款适用于Android的迷你游戏.我正在使用此代码创建一个在游戏暂停时暂停的3分钟计时器:
class update extends Thread{
@Override
public final void interrupt(){
super.interrupt();
}
@Override
public void run(){
try{
while(true){
sleep(50);
iTime++;
if(iTime>=3600)
bEnd = true; //finish
postInvalidate();
}
}catch(InterruptedException e){
}
}
}
update thread = null;
3600 = 20*3*60
Run Code Online (Sandbox Code Playgroud)
计时器在大约5分钟内完成,在大约1.5分钟后在Galaxy Tab中完成.
为什么不总是需要3分钟?我如何确保在3分钟内完成?
我使用下面的代码来创建带有复选框的对话框:
创建:
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
LayoutInflater adbInflater = LayoutInflater.from(getContext());
LinearLayout eulaLayout = (LinearLayout) adbInflater.inflate(R.layout.checkbox, null);
dontShowAgain = (CheckBox)eulaLayout.findViewById(R.id.skip);
Run Code Online (Sandbox Code Playgroud)
checbox.xml的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root" android:orientation="horizontal"
android:layout_height="fill_parent"
android:padding="10dp">
<CheckBox
android:text="Do not show again"
android:id="@+id/skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
</CheckBox>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)