小编Arb*_*ole的帖子

什么文字表达式的类型为“void”?

在 Zig 0.9 中,我需要一个类型为 的文字表达式void,用作 的上下文参数std.sort.sort,以便我的lessThan函数签名在语义上准确。有一些吗?

我尝试了这些但没有效果:

const ek = @import("std").io.getStdOut().writer();
test "void" {
    const kandidati = .{ type, u0, .{}, void, null, undefined };
    inline for (kandidati) |k|
        try ek.print("{}, ", .{@TypeOf(k)});
    try ek.print("\n", .{});
}
Run Code Online (Sandbox Code Playgroud)

给予

Test [0/1] test "void"... type, type, struct:31:37, type, @Type(.Null), @Type(.Undefined), 
All 1 tests passed.
Run Code Online (Sandbox Code Playgroud)

我不想使用像const v: void = undefined;;这样的虚拟变量 这太冗长了。

作为参考,使用带有类型参数的函数void作为上下文参数,会给出如下错误消息std.sort.sortlessThanvoid

error: expected type 'fn(type,anytype,anytype) anytype', found 'fn(void, Type1, …
Run Code Online (Sandbox Code Playgroud)

zig

2
推荐指数
1
解决办法
912
查看次数

为什么 x86 通常不允许目标寄存器不是第一个源寄存器?

在RISC-V中,可以Regs[x1] <- Regs[x2]+Regs[x3]使用指令执行整数运算

add x1,x2,x3
Run Code Online (Sandbox Code Playgroud)

在 x86 中,相同的操作显然需要两条指令,

mov x1,x2
add x1,x3
Run Code Online (Sandbox Code Playgroud)

该模式对于 x86 中的其他基本指令(例如、和 )src1 <- src1 op src2似乎很常见。然而,x86 确实有浮点数的eg 。andorsubdest <- src1 op src2add

是双指令模式mov x1,x2op x1,x3; 通常将宏融合到单个微操作中?或者,对于这些操作来说,独立目标是如此不常见,以至于 x86 架构不会费心在单个 uop 中允许它?如果是这样,禁止独立目的地会带来什么效率?

x86 assembly cpu-architecture riscv

1
推荐指数
2
解决办法
1070
查看次数

标签 统计

assembly ×1

cpu-architecture ×1

riscv ×1

x86 ×1

zig ×1