Vector literals? #1091
Replies: 4 comments 11 replies
-
I don't think we've discussed this before. We can do analysis on our internal code base; does this come up often in your experience? Something we have discussed is that it would be nice to make the integration of vectors more first class somehow, e.g. have some ways to work with vectors that doesn't require a lot of external scaffolding. Maybe that can then imply that we can do more optimizations around them... Separately, a concrete issue around specifically vector literals is that we'd need to somehow support 3-vector and 4-vector forms from the same bytecode. I don't think we should bifurcate the bytecode format, and the compiler doesn't even know right now if it's targeting 3-vector or 4-vector environment. This could be easier if for example we only support literals with a fixed 4-th component (e.g. say it's always 0 or 1) as that would make the 2-variant encoding more straighforward. |
Beta Was this translation helpful? Give feedback.
-
I don't mind having to implement our own vector operations personally, but having more first-class operations would certainly speed things up. For example, length, normalization, dot product, etc. are fairly common and could be implemented as fast calls if they were part of the VM. However, a major problem I see is that there are many kinds of conventions for these. For example, Roblox API takes an OOP approach, while our Lua bindings are completely procedural and vector functions are global functions resembling vector ops in shader languages. Perhaps a more generic solution is to allow implementing new fast-calls in user code or come up with another mechanism for doing faster native function calls (you mentioned this earlier)? We have some other hotspot application specific functions that would benefit from user specified fast-calls too. |
Beta Was this translation helpful? Give feedback.
-
Implementation seems to be fairly straightforward. Compiler and VM seems to work fine, haven't looked at codegen yet. I'll analyze performance next. Work in progress: Note: this relies on built-in folding which is only enabled on -O2. I'll extend this to a proper PR later... |
Beta Was this translation helpful? Give feedback.
-
@petrihakkinen Semi-related, but do you have any more detail about how you're using 4 component vectors? I'm also interested in having a mix of |
Beta Was this translation helpful? Give feedback.
-
Currently literal vectors always seem to generate fast-call to the vector constructor. I think it would make sense (perf. wise) to support vector literals by storing them in the constant table. Are there any plans for this?
Beta Was this translation helpful? Give feedback.
All reactions