Skip to content

verbs\va.h macros refactor into templates? #136

Description

@Sebanisu

There are a few macros in this file.

APFX

There are 139 usages across 8 files.
f is the generated function's name. Could use a c++ using to preserve the name.
Tz,Tx,Ty are all types.
pfx is a dyadic macro leading to a 2 or more argument function? (x,y) many macros provide their own 3rd arguments.
I was thinking that the pfx macro could be replaced with lambdas.
pref is a code fragment to be at start.
suff is a return argument, aka code fragment to be at end.
pref and suff could add complications for template code. You could have an encapsulating function for the pref and suff?

// suff must return the correct result
#define APFX(f, Tz, Tx, Ty, pfx, pref, suff)                                                                     \
    I f(I n, I m, Tx* RESTRICTI x, Ty* RESTRICTI y, Tz* RESTRICTI z, J jt) {                                     \
        Tx u;                                                                                                    \
        Ty v;                                                                                                    \
        pref if (n - 1 == 0) DQ(m, *z++ = pfx(*x, *y); x++; y++;) else if (n - 1 < 0)                            \
          DQ(m, u = *x++; DQC(n, *z++ = pfx(u, *y); y++;)) else DQ(m, v = *y++; DQ(n, *z++ = pfx(*x, v); x++;)); \
        suff                                                                                                     \
    }
//example
APFX(bw0000II, UI,UI,UI, BW0000,, return EVOK;) 

For refactoring just focusing on the loop inside? Working from inside out?
Probably would need to port DQ and DQC first those are basically for loops. These are in j.h

#define DQ(n,stm)       {I i=(I)(n)-1;    for(;i>=0;--i){stm}}  // i runs from n-1 downto 0 (fastest when you don't need i)
#define DQC(n,stm)       {I i=-2-(I)(n);    for(;i>=0;--i){stm}}  // i runs from n-1 downto 0 (fastest when you don't need i)

Here's how we could recode DQ and DQC: https://godbolt.org/z/jc3Yzd
Possible APFX_impl code: https://godbolt.org/z/jj7srd

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions