- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在为 android 编译一段 asm 代码:
static void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
{
__asm__ __volatile__ (
"cpuid"
: "=a" (*a) ,
"=b" (*b) ,
"=c" (*c) ,
"=d" (*d)
: "0" (function)) ;
}
APP_ABI 设置为“全部”:APP_ABI := 所有
x86编译失败:
$ ndk-build
[armeabi-v7a] Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi-v7a/gdbserver
[armeabi-v7a] Gdbsetup : libs/armeabi-v7a/gdb.setup
[armeabi] Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
[armeabi] Gdbsetup : libs/armeabi/gdb.setup
[x86] Gdbserver : [x86-4.6] libs/x86/gdbserver
[x86] Gdbsetup : libs/x86/gdb.setup
[mips] Gdbserver : [mipsel-linux-android-4.6] libs/mips/gdbserver
[mips] Gdbsetup : libs/mips/gdb.setup
[armeabi-v7a] Compile thumb : hello-jni <= CpuArch.c
[armeabi-v7a] SharedLibrary : libhello-jni.so
[armeabi-v7a] Install : libhello-jni.so => libs/armeabi-v7a/libhello-jni.so
[armeabi] Compile thumb : hello-jni <= CpuArch.c
[armeabi] SharedLibrary : libhello-jni.so
[armeabi] Install : libhello-jni.so => libs/armeabi/libhello-jni.so
[x86] Compile : hello-jni <= CpuArch.c
D:/adt/ndk/samples/hello-jni/jni/CpuArch.c: In function 'MyCPUID':
D:/adt/ndk/samples/hello-jni/jni/CpuArch.c:75:3: error: inconsistent operand constraints in an 'asm'
/cygdrive/d/adt/ndk/build/core/build-binary.mk:391: recipe for target '/cygdrive/d/adt/ndk/samples/hello-jni/obj/local/x86/objs-debug/hello-jni/CpuArch.o' failed
make: *** [/cygdrive/d/adt/ndk/samples/hello-jni/obj/local/x86/objs-debug/hello-jni/CpuArch.o] Error 1
我在 asm 方面没有太多经验。而且错误消息似乎不足以找到解决方案。 :(
顺便说一句,编译是在 win7 中使用 cygwin 进行的。
完整版:
static void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
{
#ifdef USE_ASM
#ifdef _MSC_VER
UInt32 a2, b2, c2, d2;
__asm xor EBX, EBX;
__asm xor ECX, ECX;
__asm xor EDX, EDX;
__asm mov EAX, function;
__asm cpuid;
__asm mov a2, EAX;
__asm mov b2, EBX;
__asm mov c2, ECX;
__asm mov d2, EDX;
*a = a2;
*b = b2;
*c = c2;
*d = d2;
#else
__asm__ __volatile__ (
"cpuid"
: "=a" (*a) ,
"=b" (*b) ,
"=c" (*c) ,
"=d" (*d)
: "0" (function)) ;
#endif
#else
int CPUInfo[4];
__cpuid(CPUInfo, function);
*a = CPUInfo[0];
*b = CPUInfo[1];
*c = CPUInfo[2];
*d = CPUInfo[3];
#endif
}
最佳答案
此代码基于我在 Stackoverflow answer 中编写的内容.在某些基于 x86 的架构/ABI 上,必须小心保留 %ebx
寄存器。 %ebx
用于在生成位置无关代码(-fPIC
gcc 选项)时重新定位代码(共享对象等)。下面的代码避免在扩展汇编器输出中使用 =b
并使用编译器知道是免费且可用的寄存器。 %ebx
通过在调用 cpuid
之前和之后将其交换到空闲寄存器来保留。我还修复了一个与 %ecx
寄存器相关的小错误。我将它清除为 0 ("c"(0)
),因为在某些架构上,如果不这样做,将导致 cpuid
返回陈旧的值。
static void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
{
#if defined(__i386__)
__asm__ __volatile__ (
"xchgl\t%%ebx, %k1\n\t" \
"cpuid\n\t" \
"xchgl\t%%ebx, %k1\n\t"
: "=a"(*a), "=&r"(*b), "=c"(*c), "=d"(*d)
: "a"(function), "c"(0));
#elif defined(__x86_64__)
__asm__ __volatile__ (
"xchgq\t%%rbx, %q1\n\t" \
"cpuid\n\t" \
"xchgq\t%%rbx, %q1\n\t"
: "=a"(*a), "=&r"(*b), "=c"(*c), "=d"(*d)
: "a"(function), "c"(0));
#else
#error "Unknown architecture."
#endif
}
关于c++ - android ndk asm编译错误: inconsistent operand constraints in an 'asm' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32266119/
我正在查看 SQL Server 2008 的 AdventureWorks 示例数据库,我在他们的创建脚本中看到他们倾向于使用以下内容: ALTER TABLE [Production].[Prod
我目前正在使用 PostgreSQL 9.5,想知道是否有可能在 ON CONFLICT ON CONSTRAINT 语句中包含 2 个约束的名称。我的sql如下 INSERT INTO LIVE.T
使用 htmlhelpers 可以限制你的助手将绑定(bind)到什么类型 public static HtmlString DatePicker(this HtmlHelper html,
我使用的是 Symfony 2.5,我的 Model 类如下: /** * @UserAssert\UserPasswordReset */ class ResetPassword { /** *
我有 3 个 View :A、B、C。 (A 和 B 的高度相等)开始时 B 的可见性消失,C 的顶部约束是 A 的底部,因此 C 出现在 A 下方。一段时间后,我将 A 的可见性更改为消失,将 B
在 Dojo NumberTextBox 的文档中,措辞引用了“Dojo 约束语言”,甚至包括有用的 link .不幸的是,链接指向的页面仅显示 this document has been depr
在我的表中,我有一个唯一的约束。在 hibernate 中,当我添加一个违反该约束的项目时,我想捕获它,因此它将更新而不是创建一个项目。 当我没有设置 try-catch block 时 up
我正在尝试在“或”UILabel 附近添加两条 1 像素线(由 UIViews 组成)。 除了我从 Interface Builder 中的第一张图片收到警告外,一切看起来都很好并且按预期工作: Le
我已经开始学习安卓了。我正在尝试使用 Google Map API。每次我尝试启动我的应用程序时,它都会崩溃,经过调查,我在 build.gradle 文件中发现了一个通知。 Please refer
我有自定义约束: @Target({FIELD, METHOD}) @Retention(RetentionPolicy.RUNTIME) @ConstraintComposition(Composi
我正在将 Graphql 服务器与 Prisma 一起使用。但是当我尝试运行代码时出现此错误我正在使用 const { GraphQLServer } = require('graphql-yoga'
更新到 com.android.support.constraint:constraint-layout:1.1.0 之后 约束布局崩溃说: All children of constraint la
我在 Xcode 10 中工作,在尝试向我的 View 添加一些非常简单的约束时遇到了一些错误。 我有一个 UICollectionViewCell,我正在向其添加一个 UIStackView。我调整
尝试在 Laravel 上创建一个待办事项列表应用程序,但是当我尝试单击按钮创建一个新的待办事项列表时,出现此错误: SQLSTATE[23000]: Integrity constraint vio
我正在编写一个基于网格的 View ,使用以下代码动态添加 NSLayoutConstraints for (x, column) in enumerate(board) { for (y,
我正在尝试使用 Constraint composition并希望为每个复合约束定义组,如下例所示:- 复合约束 @Target({ ElementType.FIELD, Elemen
我有一些添加了外键约束的表。它们与代码生成一起使用,以在生成的存储过程中设置特定的联接。 是否可以通过在事务中调用多个删除来覆盖这些约束,特别是 C# 中的“TransactionScope”,或者绝
我需要向现有 SQL Server 表添加约束,但前提是该表尚不存在。 我使用以下 SQL 创建约束。 ALTER TABLE [Foo] ADD CONSTRAINT [FK_Foo_Bar] FO
这是我的总输出: Executing SQL script in server ERROR: Error 1215: Cannot add foreign key constraint CREATE
我正在增加 Facebook SDK 登录按钮 (FBSDKLoginButton) 的大小。 Facebook SDK 源代码向 FBSDKLoginButton 添加了一个约束,height =
我是一名优秀的程序员,十分优秀!