Duplicating source code

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

I preprocess source code, usually with awk but some IDEs allow complex regex substitutions, macros or plugins. I'm bad at writing standardized code so the scripts sort it out, flags my common mistakes (excessive recursion, malloc abuse etc.), make variable names consistent and substitute in function/procedure calls for inline (with appropriate parameter modding). It allows me to prototype quickly and than generate standards specific source.

This is old school, but so am I and it works.
I miss MindPrint. My TRIO needs a big brother.

Post

in gcc you could check out -Winline and -finline-functions
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!

irc.libera.chat >>> #kvr

Post

With that force-inline thing you forget about that there are CPUs where -Os (optimize for size) is faster than -O2 (optimize for speed).
There is a reason for why they have introduced Thumb instructions on ARM.

As Miles1981 says, the compiler knows best about when to inline and when not.
In additon to your force inline instructions, it might also consider stuff like the optimization level, target processor / architecture, ect pp.
I remeber that the force-inline on MSVC only gives a stronger hint to inline this than a normal inline statement. But it nowhere forces the compiler to inline, the final decission is made by the compiler not by you. Don't know what gcc does, but I assume it does same. Otherwise you could easily end up with executables of [n] GB size, just because you added your force-inlines at the wrong places.

Post

PurpleSunray wrote:As Miles1981 say, the compiler knows best about when to inline and when not.
In additon to your force inline instructions, it might also consider stuff like the optimization level, target processor / architecture, ect pp.
No, unless you use a custom compiler, they are generic and compatibility based. Even, with specific settings they are still not optimal.

It is up to the coder when to use inline, when to multi-thread, when to switch to assembly, when to use vectors. Letting a compiler decide is just lax as there are environmental factors it can't know about.

I include metrics in prototype code so I can decide which are the best options. I have templates to start with (daemon, sync/async threads, vector etc.) then include metric based dynamic settings to further decide as the code is running. I can then preprocess and create a make file based upon the data.

I'll admit that this maybe overkill for most, but I started as an real-time (SCADA) software engineer so it's automatic to me now.
I miss MindPrint. My TRIO needs a big brother.

Post

khanyz wrote: No, unless you use a custom compiler, they are generic and compatibility based. Even, with specific settings they are still not optimal.
What is a custom compiler?
I can do "gcc -march=i686", or "gcc -march=armv6"
Same compiler, but produces very different code. So gcc is a customer compiler?

To play this game even further, what if I do "gcc -march=armv6 -mthumb-interwork -Os .." basically I tell the compiler to produce an executable that is as small as possible.
Because mem throughput on my little ARM CPU sucks balls. I will gain way more speed by keeping executable as small as possible, compared to big executable with lots of inlines.
If I feed your force-inline code into that gcc and your force-inline actually forces inlines, it negates all of my settings from above. gcc cannot optimize for size, because you already optimized for speed via force-inline.

Post

PurpleSunray wrote: What is a custom compiler?
I can do "gcc -march=i686", or "gcc -march=armv6"
Same compiler, but produces very different code. So gcc is a customer compiler?
A custom compiler is for a specific platform and/or purpose. It is completely different from a general compiler which can be altered with settings, although there have been pseudo-custom ones which were just wrappers to generic+settings.

Also, it's not a game, it's called learning your craft. In the situation you mention, I wouldn't have used inline because of the environment. It would be stupid to do so, just as the example is.

I've coded many a Symbian brick so have templates for such occasions.
I miss MindPrint. My TRIO needs a big brother.

Post

Hm, ok than I need to re-learn about compiles.
Have never seen such a "generic compiler" so far (I mean one that can output code that runs on multiple platforms).

If I use clang instead of gcc, LLVM bitcode is what I would consider as generic code.
But this it is what the frontend produces. The linker does not output generic code, but code for a specific platform.
In the situation you mention, I wouldn't have used inline because of the environment
Question:
You write a libmp3dec. It is an mp3 decoder, in C.
How do you know about the environment?
The environment is know when you compile / build for that environment, not when you write code.
Or are you going to code libmp3dec_x386, libmp3dec_x86_sse, libmpdec_armv6, libmp3dec_armv7, libmp3dec_armv7s, libmp3dec_armv7s_snapdragon_optimized_for_size, libmp3dec_AVR .... ?

Post

PurpleSunray wrote:Hm, ok than I need to re-learn about compiles.
Have never seen such a "generic compiler" so far (I mean one that can output code that runs on multiple platforms).

If I use clang instead of gcc, LLVM bitcode is what I would consider as generic code.
But this it is what the frontend produces. The linker does not output generic code, but code for a specific platform.
In the situation you mention, I wouldn't have used inline because of the environment
Question:
You write a libmp3dec. It is an mp3 decoder, in C.
How do you know about the environment?
The environment is know when you compile / build for that environment, not when you write code.
Or are you going to code libmp3dec_x386, libmp3dec_x86_sse, libmpdec_armv6, libmp3dec_armv7, libmp3dec_armv7s, libmp3dec_armv7s_snapdragon_optimized_for_size, libmp3dec_AVR .... ?
I think you need to read up to compilation and compilers as you seem a bit confused and it would take too long to explain. Although, basically, you've never seen a custom compiler, gcc is a generic one.

As for your question, libraries are different because they can need to work in multiple enviroments and/or platforms. That's why you can have multiple versions, such as static/dynamic and per platform. They would have lots of shared code, however, I would hope that you have different code (signified by ifdefs) for common attributes like word-length, character coding, console/GUI (probably deprecated).
I miss MindPrint. My TRIO needs a big brother.

Post

khanyz wrote: I think you need to read up to compilation and compilers as you seem a bit confused and it would take too long to explain. Although, basically, you've never seen a custom compiler, gcc is a generic one.
Well, to make it easy:
Please send me a binary, compiled with gcc, that runs on my PC (x64) and on my phone (armv7s) at the same time.
I would like to have a look on that onw my own.
Or simply tell me gcc comand line to compile something like that. Do generic build for x86 and armv7s.
As for your question, libraries are different because they can need to work in multiple enviroments and/or platforms. That's why you can have multiple versions, such as static/dynamic. However, I would hope that you have different code (signified by ifdefs) for common attributes like word-length, character coding, console/GUI (probably deprecated).
On my libmp3dec, there is a dct.c
If I compile it for x386, compiler will output plain x86 instructions.
If I compile it for x86 with SSE support, compiler will output x86 with SSE instructions.
If I compile it for ARM no-thumb, compiler will output ARM no-thumb instructions.
If I compile it for ARM thumb, compiler will output ARM thumb instructions.
Sorry, but my compiler is not generic at all.
I need to tell it for what platform I want to compile for.

Ofc I also have #ifdefs.. there is a dct_sse.asm that does same like the C code, but it is hand-crafted SSE code.
Than there is a dct_neon.asm that has hand-crafted code for ARM CPU with NEON support. ect pp.
But that's not the point here.
The point is that a compiler needs to know about the target platform.
It will output instructions for that target platfrom.
It will not output generic instructions that run on every platfrom.

That is what Java or .NET is about, but talk we about native code.
Last edited by PurpleSunray on Wed May 24, 2017 4:57 pm, edited 3 times in total.

Post

In the past Apple had an idea of "fat" binaries that contained both PowerPC and Intel code, but apparently it has never been popular as PowerPC seems to have became unpopular quite rapidly by that time. Is that a custom compiler? Well yes, somebody (Apple ) had modified gcc to do that. So never say never:)
~stratum~

Post

@stratum:
It still exists (the concept, the name and actual implementatoin is different now).
It's used on iOS and/or Android.
Different Phones can have different CPU types.
So if you donwload an App from Apple or Play Store that has native code, you actually get an archive that has binaries for all architectures.
To get your native app into the Apple Store, you need to provide x86 (for iOS simulator), armv7 (for very old iPhones), armv7s (for old iPhones) and armv8 (for new iPhones) binaries at least.
Too bad there is no generic compiler.. could provide a generic binary of all, instead of 4 binaries for 4 different CPUs.

Post

stratum wrote:In the past Apple had an idea of "fat" binaries that contained both PowerPC and Intel code, but apparently it has never been popular as PowerPC seems to have became unpopular quite rapidly by that time. Is that a custom compiler? Well yes, somebody (Apple ) had modified gcc to do that. So never say never:)
And you still have universal binaries for i386/x86_64 :p

Post

.<edit>.

Post

Another example of something I would like to do on the source code level is write an iteration to create a dataset. Instead of it actually compiling an iteration, the parser would see it as a source code level event and expand it in a way that makes sense... anything like this possible?

Post

antto wrote:in gcc you could check out -Winline and -finline-functions
Will -Winline notify of any function marked for inlining that couldn't be inlined? There are cases where inlining will not work (example, computed goto, has to be local (in source)), but for the rest, does it silently ignore them?

Post Reply

Return to “DSP and Plugin Development”