Skip to content

Request: flag output #14

Open
Open
@nicbn

Description

@nicbn

To branch off a flag, this is the current way (x86):

let mut r: u8;

asm!(
    "cmp {a}, {b}",
    "sete {r}",

    r = out(reg_byte) r,
    a = in(reg) a,
    b = in(reg) b,
);

let r: bool = mem::transmute(r); // Matching r and using unreachable_unchecked() also works
if r { ... } else { ... }

This causes a test on the r register, and then, in most cases, a jump conditional is called. Ideally, this whole r register would not be a thing and we could just jump conditional right after calling the asm!.

This optmization, however, can not happen because there are no ways of outputting a flag from asm. GCC has an extension which allows it to do this very thing. The desired syntax would be something along the lines of out("z") r, with r: bool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions