@@ -432,12 +432,12 @@ class Compiler {
432432 bool mirror;
433433 bool cached;
434434 Context (
435- const std::string &expr,
436- const VSVideoInfo *vo,
437- const VSVideoInfo *const *vi,
435+ const std::string &expr,
436+ const VSVideoInfo *vo,
437+ const VSVideoInfo *const *vi,
438438 const VSAPI *vsapi,
439- int numInputs,
440- int opt,
439+ int numInputs,
440+ int opt,
441441 int mirror
442442 ):
443443 expr (expr), vo(vo), vi(vi), vsapi(vsapi), numInputs(numInputs), optMask(opt), mirror(!!mirror), cached(false ) {
@@ -487,13 +487,10 @@ class Compiler {
487487 using ftype = rr::ModuleFunction<FloatV(FloatV)>;
488488 using ftype2 = rr::ModuleFunction<FloatV(FloatV, FloatV)>;
489489 std::unique_ptr<ftype> Exp;
490- std::unique_ptr<ftype> Log;
491490 std::unique_ptr<ftype> Sin;
492491 std::unique_ptr<ftype> Cos;
493- std::unique_ptr<ftype2> Pow;
494492 };
495493 rr::RValue<FloatV> Exp_ (rr::RValue<FloatV>);
496- rr::RValue<FloatV> Log_ (rr::RValue<FloatV>);
497494 rr::RValue<FloatV> SinCos_ (rr::RValue<FloatV>, bool issin);
498495 rr::RValue<FloatV> FP16To32 (rr::RValue<UShortV>);
499496 rr::RValue<UShortV> FP32To16 (rr::RValue<FloatV>);
@@ -546,11 +543,11 @@ class Compiler {
546543public:
547544 Compiler (
548545 const std::string &expr,
549- const VSVideoInfo *vo,
550- const VSVideoInfo * const *vi,
546+ const VSVideoInfo *vo,
547+ const VSVideoInfo * const *vi,
551548 const VSAPI *vsapi,
552- int numInputs,
553- int opt = 0 ,
549+ int numInputs,
550+ int opt = 0 ,
554551 int mirror = 0
555552 ) : ctx(expr, vo, vi, vsapi, numInputs, opt, mirror) {}
556553
@@ -591,51 +588,6 @@ rr::RValue<typename Compiler<lanes>::FloatV> Compiler<lanes>::Exp_(rr::RValue<ty
591588 return x;
592589}
593590
594- template <int lanes>
595- rr::RValue<typename Compiler<lanes>::FloatV> Compiler<lanes>::Log_(rr::RValue<typename Compiler<lanes>::FloatV> x_)
596- {
597- FloatV x = x_;
598- using namespace rr ;
599- const uint32_t min_norm_pos = 0x00800000 , inv_mant_mask = ~0x7F800000 ;
600- const float float_half = 0 .5f , sqrt_1_2 = 0 .707106781186547524f , log_p0 = 7 .0376836292E-2f , log_p1 = -1 .1514610310E-1f ,
601- log_p2 = 1 .1676998740E-1f , log_p3 = -1 .2420140846E-1f , log_p4 = +1 .4249322787E-1f , log_p5 = -1 .6668057665E-1f ,
602- log_p6 = +2 .0000714765E-1f , log_p7 = -2 .4999993993E-1f , log_p8 = +3 .3333331174E-1f , log_q2 = 0 .693359375f ,
603- log_q1 = -2 .12194440e-4f ;
604- const float zero = 0 .0f , one = 1 .0f ;
605- IntV invalid_mask = CmpLE (x, FloatV (zero));
606- x = Max (x, As<FloatV>(IntV (min_norm_pos)));
607- IntV emm0i = As<IntV>(x) >> 23 ;
608- x = As<FloatV>(As<IntV>(x) & IntV (inv_mant_mask));
609- x = As<FloatV>(As<IntV>(x) | As<IntV>(FloatV (float_half)));
610- emm0i = emm0i - IntV (0x7f );
611- FloatV emm0 = FloatV (emm0i);
612- emm0 = emm0 + FloatV (one);
613- IntV mask = CmpLT (x, FloatV (sqrt_1_2));
614- FloatV etmp = As<FloatV>(mask & As<IntV>(x));
615- x = x - FloatV (one);
616- FloatV maskf = As<FloatV>(mask & As<IntV>(FloatV (one)));
617- emm0 = emm0 - maskf;
618- x = x + etmp;
619- FloatV z = x * x;
620- FloatV y = FloatV (log_p0);
621- y = FMA (y, x, FloatV (log_p1));
622- y = FMA (y, x, FloatV (log_p2));
623- y = FMA (y, x, FloatV (log_p3));
624- y = FMA (y, x, FloatV (log_p4));
625- y = FMA (y, x, FloatV (log_p5));
626- y = FMA (y, x, FloatV (log_p6));
627- y = FMA (y, x, FloatV (log_p7));
628- y = FMA (y, x, FloatV (log_p8));
629- y = y * x;
630- y = y * z;
631- y = FMA (emm0, FloatV (log_q1), y);
632- y = FMA (z, FloatV (-float_half), y);
633- x = x + y;
634- x = FMA (emm0, FloatV (log_q2), x);
635- x = As<FloatV>(invalid_mask | As<IntV>(x));
636- return x;
637- }
638-
639591template <int lanes>
640592rr::RValue<typename Compiler<lanes>::FloatV> Compiler<lanes>::SinCos_(rr::RValue<typename Compiler<lanes>::FloatV> x_, bool issin)
641593{
@@ -1196,16 +1148,14 @@ void Compiler<lanes>::buildOneIter(const Helper &helpers, State &state)
11961148 case ExprOpType::FLOOR : UNARYOPF (Floor);
11971149
11981150 case ExprOpType::EXP : UNARYOPF ([&helpers](RValue<FloatV> x) -> FloatV { return helpers.Exp ->Call (x); });
1199- case ExprOpType::LOG : UNARYOPF ([&helpers](RValue<FloatV> x) -> FloatV { return helpers.Log ->Call (x); });
1151+ case ExprOpType::LOG : {
1152+ LOAD1 (x);
1153+ OUT (Log (x.ensureFloat ()));
1154+ break ;
1155+ }
12001156 case ExprOpType::POW : {
12011157 LOAD2 (l, r);
1202- if (!r.isFloat ()) {
1203- OUT (IfThenElse (RValue<IntV>(r.i ()).IsConstant (),
1204- BuiltinPow (l.ensureFloat (), FloatV (r.i ())),
1205- helpers.Pow ->Call (l.ensureFloat (), r.ensureFloat ())));
1206- } else {
1207- OUT (helpers.Pow ->Call (l.ensureFloat (), r.ensureFloat ()));
1208- }
1158+ OUT (Pow (l.ensureFloat (), r.ensureFloat ()));
12091159 break ;
12101160 }
12111161 case ExprOpType::SIN : UNARYOPF ([&helpers](RValue<FloatV> x) -> FloatV { return helpers.Sin ->Call (x); });
@@ -1300,19 +1250,6 @@ typename Compiler<lanes>::Helper Compiler<lanes>::buildHelpers(rr::Module &mod)
13001250 FloatV x = h.Sin ->template Arg <0 >();
13011251 Return (Exp_ (x));
13021252 }
1303- h.Log = std::make_unique<ftype>(mod, " vlog" );
1304- h.Log ->setPure ();
1305- {
1306- FloatV x = h.Sin ->template Arg <0 >();
1307- Return (Log_ (x));
1308- }
1309- h.Pow = std::make_unique<ftype2>(mod, " vpow" );
1310- h.Pow ->setPure ();
1311- {
1312- FloatV x = h.Pow ->template Arg <0 >();
1313- FloatV y = h.Pow ->template Arg <1 >();
1314- Return (h.Exp ->Call (h.Log ->Call (x) * y));
1315- }
13161253
13171254 return h;
13181255}
@@ -1530,12 +1467,12 @@ static void VS_CC exprCreate(const VSMap *in, VSMap *out, void *userData, VSCore
15301467 if (d->vi .format .numPlanes != f.numPlanes )
15311468 throw std::runtime_error (" The number of planes in the inputs and output must match" );
15321469 vsapi->queryVideoFormat (
1533- &d->vi .format ,
1534- d->vi .format .colorFamily ,
1535- f.sampleType ,
1536- f.bitsPerSample ,
1537- d->vi .format .subSamplingW ,
1538- d->vi .format .subSamplingH ,
1470+ &d->vi .format ,
1471+ d->vi .format .colorFamily ,
1472+ f.sampleType ,
1473+ f.bitsPerSample ,
1474+ d->vi .format .subSamplingW ,
1475+ d->vi .format .subSamplingH ,
15391476 core
15401477 );
15411478 }
0 commit comments