DSPRelated.com
Forums

Brain going numb

Started by Unknown January 29, 2013
I am working on this brain numbing task where I have to simplify loooooong expressions like this:

 coef = ((((((((((inv_nrg >> 16) * (int)((short)nl)) + (((inv_nrg & 0x0000FFFF) * (int)((short)nl)) >> 16)))) + ((inv_nrg * ((16 == 1 ? (nl >> 1) + (nl & 1) : ((nl >> 15) + 1) >> 1)))))) >> 16) * (int)((short)(1024 << 1))) + ((((((((((inv_nrg >> 16) * (int)((short)nl)) + (((inv_nrg & 0x0000FFFF) * (int)((short)nl)) >> 16)))) + ((inv_nrg * ((16 == 1 ? (nl >> 1) + (nl & 1) : ((nl >> 15) + 1) >> 1)))))) & 0x0000FFFF) * (int)((short)(1024 << 1))) >> 16));
      }


There must be a tool out there which can take the above expression, chew on it and spit out a more clean and simple expression?

Please help me - my brain is going numb!!!

A tool which can scan through a bunch of C files and simplify expressions would be awesome - but I don't know if that exists?


j21341234@gmail.com wrote:
> I am working on this brain numbing task where I have to simplify loooooong expressions like this: > > coef = ((((((((((inv_nrg >> 16) * (int)((short)nl)) + (((inv_nrg & 0x0000FFFF) * (int)((short)nl)) >> 16)))) + ((inv_nrg * ((16 == 1 ? (nl >> 1) + (nl & 1) : ((nl >> 15) + 1) >> 1)))))) >> 16) * (int)((short)(1024 << 1))) + ((((((((((inv_nrg >> 16) * (int)((short)nl)) + (((inv_nrg & 0x0000FFFF) * (int)((short)nl)) >> 16)))) + ((inv_nrg * ((16 == 1 ? (nl >> 1) + (nl & 1) : ((nl >> 15) + 1) >> 1)))))) & 0x0000FFFF) * (int)((short)(1024 << 1))) >> 16)); > } > > > There must be a tool out there which can take the above expression, chew on it and spit out a more clean and simple expression? > > Please help me - my brain is going numb!!! > > A tool which can scan through a bunch of C files and simplify expressions would be awesome - but I don't know if that exists? > >
Why would you think there would be such a thing? -- Les Cargill
Is this the output of some tool that does bit-exact simulation in C?
Because I'm probably not the first person who have asked this question?
> Is this the output of some tool that does bit-exact simulation in C?
It's the output of a pre-processor. Totally messy. Trying to clean it up and then optimize it. Don't ask why I'm doing this. I just need a tool to simplify the expressions for me or else I have to manually do it -- which is putting me to sleep.
<j21341234@gmail.com> wrote:

>I am working on this brain numbing task where I have to simplify loooooong >expressions like this: >coef = ((((((((((inv_nrg >> 16) * (int)((short)nl)) + (((inv_nrg & >0x0000FFFF) * (int)((short)nl)) >> 16)))) >There must be a tool out there which can take the above expression, chew on >it and spit out a more clean and simple expression? >Please help me - my brain is going numb!!!
Hacking a code from obfuscator ? Better find different job. VLV
On 1/29/13 1:39 PM, Les Cargill wrote:
> j21341234@gmail.com wrote: >> I am working on this brain numbing task where I have to simplify >> loooooong expressions like this: >> >> coef = ((((((((((inv_nrg >> 16) * (int)((short)nl)) + (((inv_nrg & >> 0x0000FFFF) * (int)((short)nl)) >> 16)))) + ((inv_nrg * ((16 == 1 ? >> (nl >> 1) + (nl & 1) : ((nl >> 15) + 1) >> 1)))))) >> 16) * >> (int)((short)(1024 << 1))) + ((((((((((inv_nrg >> 16) * >> (int)((short)nl)) + (((inv_nrg & 0x0000FFFF) * (int)((short)nl)) >> >> 16)))) + ((inv_nrg * ((16 == 1 ? (nl >> 1) + (nl & 1) : ((nl >> 15) + >> 1) >> 1)))))) & 0x0000FFFF) * (int)((short)(1024 << 1))) >> 16)); >> } >> >> >> There must be a tool out there which can take the above expression, >> chew on it and spit out a more clean and simple expression? >> >> Please help me - my brain is going numb!!! >> >> A tool which can scan through a bunch of C files and simplify >> expressions would be awesome - but I don't know if that exists? >> >> > > > Why would you think there would be such a thing? >
i'm wondering if something like this is what might come outa a "disassembler" like MacNosy used to be. i think, it's more like what comes outa a C++ to C translator. they used to call it "mangled" code or something like that, i thought. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
On 1/29/13 2:49 PM, j21341234@gmail.com wrote:
>> Is this the output of some tool that does bit-exact simulation in C? > > It's the output of a pre-processor.
so the original source is C++?
> Totally messy. Trying to clean it up and then optimize it. Don't ask why I'm doing this. I just need a tool to simplify the expressions for me or else I have to manually do it -- which is putting me to sleep.
i think it would make a lot more sense start with the original C++ (or whatever) code. but if you have to do that, replace each tertiary case expression (with the ? and : symbols) with a variable and define that variable with an if/else statement. rot's o' ruk. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
"robert bristow-johnson" <rbj@audioimagination.com> wrote in message 
news:ke9ipd$8vp$1@dont-email.me...
> On 1/29/13 2:49 PM, j21341234@gmail.com wrote: >>> Is this the output of some tool that does bit-exact simulation in C? >> >> It's the output of a pre-processor. > > so the original source is C++? > >> Totally messy. Trying to clean it up and then optimize it. Don't ask why >> I'm doing this. I just need a tool to simplify the expressions for me or >> else I have to manually do it -- which is putting me to sleep. > > i think it would make a lot more sense start with the original C++ (or > whatever) code. but if you have to do that, replace each tertiary case > expression (with the ? and : symbols) with a variable and define that > variable with an if/else statement.
Heh. This is what the obfuscator tool does: messes up the original source code so it would be incomprehensible. So, the obfuscated source could be published, but it would be nearly useless for anyone who wants to modify or study it. Technically, this satisfies the open source policies. VLV
On 1/29/13 5:57 PM, Vladimir Vassilevsky wrote:
> "robert bristow-johnson"<rbj@audioimagination.com> wrote in message > news:ke9ipd$8vp$1@dont-email.me... >> On 1/29/13 2:49 PM, j21341234@gmail.com wrote: >>>> Is this the output of some tool that does bit-exact simulation in C? >>> >>> It's the output of a pre-processor. >> >> so the original source is C++? >> >>> Totally messy. Trying to clean it up and then optimize it. Don't ask why >>> I'm doing this. I just need a tool to simplify the expressions for me or >>> else I have to manually do it -- which is putting me to sleep. >> >> i think it would make a lot more sense start with the original C++ (or >> whatever) code. but if you have to do that, replace each tertiary case >> expression (with the ? and : symbols) with a variable and define that >> variable with an if/else statement. > > Heh. This is what the obfuscator tool does: messes up the original source > code so it would be incomprehensible. So, the obfuscated source could be > published, but it would be nearly useless for anyone who wants to modify or > study it. Technically, this satisfies the open source policies. >
well, i learn something new every day. i *have* written an obfuscator myself to mangle labels and such that go into a COFF file with the linkable machine code. so they could disassemble code but not get any meaningful labels except for the selected labels where parameters go in or out. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."