Re: [PATCH 01/16] perf: Unified API to record selective sets ofarch registers

From: Peter Zijlstra
Date: Thu May 24 2012 - 05:44:00 EST


On Wed, 2012-05-23 at 21:32 +0200, Jiri Olsa wrote:
> +static inline u64 perf_reg_value(struct pt_regs *regs, int idx)
> +{
> + switch (idx) {
> + case PERF_X86_32_REG_EAX:
> + return regs->ax;
> + case PERF_X86_32_REG_EBX:
> + return regs->bx;
> + case PERF_X86_32_REG_ECX:
> + return regs->cx;
> + case PERF_X86_32_REG_EDX:
> + return regs->dx;
> + case PERF_X86_32_REG_ESI:
> + return regs->si;
> + case PERF_X86_32_REG_EDI:
> + return regs->di;
> + case PERF_X86_32_REG_EBP:
> + return regs->bp;
> + case PERF_X86_32_REG_ESP:
> + return regs->sp;
> + case PERF_X86_32_REG_EIP:
> + return regs->ip;
> + case PERF_X86_32_REG_FLAGS:
> + return regs->flags;
> + case PERF_X86_32_REG_CS:
> + return regs->cs;
> + case PERF_X86_32_REG_DS:
> + return regs->ds;
> + case PERF_X86_32_REG_ES:
> + return regs->es;
> + case PERF_X86_32_REG_FS:
> + return regs->fs;
> + case PERF_X86_32_REG_GS:
> + return regs->gs;
> + }
> +
> + return 0;
> +}

This is just sad... is there really no saner way to write this? I
suppose you're going to iterate your sample_regs bitmap and call this
function for every bit. GCC isn't known to generate particularly sane
code for switches :/

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/