This comes in a separate patch to a) show that it is very easy
to add the new primitives, and b) add some documentation.

So the new lo/hi primitives act as undocumented lowest/highest
but actually work.

Say, both

        process = lowest;
and
        process = internal.lo;

output

        output0[i0] = FAUSTFLOAT(-1.0f);

But, say,

        process = +(1) : lowest;

crashes the compiler, while

        process = +(1) : internal.lo;

correctly outputs

        output0[i0] = FAUSTFLOAT(0.0f);

(I guess the implementation of lowest/highest is not finished,
 with this patch this code can be removed).

//------------------------------------------------------------
Example:

        ge(x,y) = internal.lo(x) >= internal.hi(y);

returns 1 if the compiler can deduce at compile time that x >= y,
otherwise 0. So

        process = _,_ <: _,_, +(1),-(1) : ge,ge;

does not generate any code and outputs

        output0[i0] = FAUSTFLOAT(0);
        output1[i0] = FAUSTFLOAT(1);

Again, I don't think it is possible to implement this in faust.
---
 compiler/extended/internalprim.hh | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/compiler/extended/internalprim.hh 
b/compiler/extended/internalprim.hh
index eae9a6528..145970081 100644
--- a/compiler/extended/internalprim.hh
+++ b/compiler/extended/internalprim.hh
@@ -23,7 +23,7 @@
 #include "simplify.hh"
 #include "sigorderrules.hh"
 
-enum InternalOp { kId, kRate };
+enum InternalOp { kId, kRate, kLo, kHi };
 
 class InternalPrim : public xtended {
     private:
@@ -43,6 +43,11 @@ class InternalPrim : public xtended {
                case kRate:
                        ret = getSigOrder(sig);
                        break;
+               case kLo: case kHi: {
+                       typeAnnotation(sig, false);
+                       interval i = getCertifiedSigType(sig)->getInterval();
+                       return tree(fOp == kLo ? i.lo() : i.hi());
+               }
                default:
                        faustassert(false);
                }
@@ -90,6 +95,8 @@ static Tree mkInternalEnv()
 
        defs = add_internal_def(defs, kId, "id");
        defs = add_internal_def(defs, kRate, "rate");
+       defs = add_internal_def(defs, kLo, "lo");
+       defs = add_internal_def(defs, kHi, "hi");
 
        return boxWithLocalDef(boxEnvironment(), defs);
 }
-- 
2.41.0



_______________________________________________
Faudiostream-devel mailing list
Faudiostream-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/faudiostream-devel

Reply via email to