Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to strip data #304

Open
zesterer opened this issue Sep 19, 2024 · 8 comments
Open

Add the ability to strip data #304

zesterer opened this issue Sep 19, 2024 · 8 comments

Comments

@zesterer
Copy link

zesterer commented Sep 19, 2024

I'm writing code that's making considerable use of LUTs generated inline via const code. As a result, I end up with the LUT data being displayed inline with the code, which is often many thousands of times larger than the code itself. It would be useful to have the option to strip data or - even better - data over a specific length from the output.

EDIT:

For anybody with a similar problem, my solution for now is:

cargo asm ... | grep -v "asciz"

which strips all lines containing asciz from the output (if your assembly language uses another keyword to denote data, use that instead). You will also want to add --color to the cargo command to retain colour output.

@pacak
Copy link
Owner

pacak commented Sep 19, 2024

Do you have an example to reproduce the problem?

@zesterer
Copy link
Author

zesterer commented Sep 19, 2024

Not that I can easily extract. Something like this should work on your end though:

fn square(x: usize) -> usize {
    let lut = const {
        let mut lut = [0; 4096];
        let mut i = 0;
        while i < 4096 {
            lut[i] = i * i;
        }
        lut
    };
    lut[x]
}

It might be worth noting that I'm compiling for an ARM-based platform so perhaps the way the compiler treats static data might be a little different given the differences in addressing mode (ARM only really supports near addresses without building up a pointer manually in a register).

@pacak
Copy link
Owner

pacak commented Sep 19, 2024

On x86 this generates a huge table but it goes into a separate section so output is still perfectly readable. Can you post some sample output of how it looks on arm? Preferably something not too huge?

@zesterer
Copy link
Author

Here's an example. Note the extremely long lines which, when displayed in a terminal, wrap.

@pacak
Copy link
Owner

pacak commented Sep 19, 2024

Here's an example.

Is that the output from cargo-show-asm? Those tables go into separate sections and I expect them not to be displayed by default.

@pacak
Copy link
Owner

pacak commented Sep 19, 2024

If it dumps in a single line I'd use something like cargo asm ... --color | less -SR

@pacak
Copy link
Owner

pacak commented Sep 19, 2024

Anyway, I don't mind adding something to deal with this issue, but only if it can't be solved with less as I shown above.

@zesterer
Copy link
Author

zesterer commented Sep 19, 2024

In theory I can process the output in any number of ways, but I think an option like --code-only would be fairly consistent with the existing features of the crate (such as --simplify).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@pacak @zesterer and others