tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Request: __attribute__((vector_size))


From: Rasmus Riiner
Subject: Re: [Tinycc-devel] Request: __attribute__((vector_size))
Date: Thu, 09 Jan 2020 13:34:50 +0200
User-agent: Mail.ee Webmail

I would say that it is okay to generate low quality code, that it's better than nothing, as long the implementation doesn't impact the rest of the compiler too much... but of course that is from my biased point of view.

Which is that the only thing presently keeping TCC compile times out of my reach is that a bunch of code akin to this in C++:

    vec2 v4 = vel + a3 * dt;
    vec2 p4 = pos + v4 * dt;
    vec2 a4 = entity_acceleration(p4, v4, entity);

    *dpos = (v1 + (v2 + v3) * 2.0 + v4) * (dt * (1.0 / 6.0));
    *dvel = (a1 + (a2 + a3) * 2.0 + a4) * (dt * (1.0 / 6.0));


Would have to be rewritten to something like this for plain C:

    vec2 v4 = v2Add(vel + v2Scale(a3 * dt));
    vec2 p4 = v2Add(pos + v2Scale(v4 * dt));
    vec2 a4 = entity_acceleration(p4, v4, entity);

    *dpos = v2Scale(v2Add(v2Add(v1, v2Scale(v2Add(v2, v3), 2.0)), v4), dt * (1.0 / 6.0));
    *dvel = v2Scale(v2Add(v2Add(a1, v2Scale(v2Add(a2, a3), 2.0)), a4), dt * (1.0 / 6.0));


Operator overloading doesn't fit C, and I'm glad it's not in there, but then the only way to fix this particular inefficiency is with some kind of built-in array math, perhaps as an extension... which is exactly what the GCC extension would provide. The extension goes a bit too far perhaps, what with supporting every basic type as a vector element, I can see why they did that though. For TCC, it might be sensible to limit the possible element types to 32bit floats or integers, and cap the possible vector length to 4...

I'm not sure what I would do in your position, implementing the extension (or a subset of it) might not be what's ultimately best for the project, but hopefully you can see where I'm coming from. Compile times for basic C++ programs take entire seconds with the available compilers, whereas I could literally tcc -run and be in-game, with immediate feedback, nearly instantly.
I could bite the bullet and start using function syntax for basic vector operations, I just wanted to confirm whether the GCC extension is outside the scope of TCC, or not, first. I don't actually use any C++ features over C, other than operator overloading and a little bit of function overloading (which I could do just fine without). It feels like so close, yet so far, you know?

Rasmus.

----- Reply to message -----
Sure, Rasmus asked to have this extension in TCC to be able to use it for
writing libraries or apps; i.e. he asked if TCC could be extended to
compile code like this:

---------------------
typedef int v4si __attribute__ ((vector_size (16)));
void foo (void) {
v4si a = {1,2,3,4}, b = {5,6,7,8}, c;
c = a + b;
bar(c[0], c[1], c[2], c[3]);
}
---------------------

For that TCC would need to be extended somewhat, and I was alluding to the
fact that this extension isn't totally trivial if it shouldn't generate
very low quality code. If it's okay to generate low quality code and
not adhere to the psABI for parameter passing of these types then it's not
too much work.

If you were asking if such extension is really a must have in a
compiler: no, otherwise it wouldn't be an extension. It's a nice to have,
and I can see why Rasmus wants it, but it comes at a non-trivial cost to
support it in a small compiler.


Ciao,
Michael.
 
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]