PDA

View Full Version : Recommended MEMSET primer?

James Slanger
06-19-2018, 12:10 PM
Does anyone have a recommended educational source on using memsets as multi-dimensional arrays? Trying to wrap my head around EEL and the best way to implement arrays.

mschnell
06-19-2018, 12:33 PM
Two dimensional array:

a = 12345; // some number denoting the start of the array in memory. Can be 0 if you only need a single array
n = 100; // the first index ruins 0.. 99
a[i+j*n] = value;

-Michael

James Slanger
06-19-2018, 02:02 PM
Thanks Michael! I should have paid more attention in my CS for Musicians course...
One more basic question, how big is each memory slot? Sizeof(double)? Specifically how many bit flags can I store in each slot?

James Slanger
06-19-2018, 03:10 PM
For anyone else looking for similar fundamentals, it just occured to me to use search terms with “JSFX EEL” instead of “OSCii bot.” Most of my questions have been asked and answered on the JSFX forum.

mschnell
06-19-2018, 09:23 PM
Each slot is a floating point number. I once used such EEL floating point number to store Bytes (in fact JSFX sliders for characters of text), and found that I could store five bytes in each. So I suppose it's safe that here are least 40 bits in the mantissa. I guess in fact it should be 47 before it gets unnormalized, plus the sign and the exponent and the exponent's sign, which would be tricky to access.

For such numbers beware of the fact that EEL uses a "soft" compare with any "==" or equivalent compares. Here the symbol "===" is provided for binary compare.

-Michael

mschnell
06-20-2018, 07:23 AM
I just did a test and what I said seems not to be correct.

I found that 1<<31 is negative and 1<< 32 is zero.

So eel seems to do logical operations with 32 bit even on reaper 64 bit

But using multiplications, you seem to be able to store 52 bits in a slot:

descr: test1
@init
x = 0;
xf1 = 0;
xf2 = 0;
y = 0;
z = 0;
yf = 1;
yfa = 1;
loop(52,
y = 1 << z;
y != 0 ? (
x += 1;
);
yf = yf * 2;
yfa = yf + 1;
yfb = yfa - 1;
yf == yfb ? (
xf1 += 1;
);
yf === yfb ? (
xf2 += 1;
);
z += 1;
);

Try changing the 52 to e.g. 53 :)

-Michael

James Slanger
06-22-2018, 02:17 PM
Thank you again Micheal!

How do we get a bitwise NOT in EEL? While working out my bit masks, ! ing my masks results in all 0's.
Some of the masks, binary print function, and test calls:

function printAsBinary(memSlot) (

loop(32,
memSlot & MSB_MASK ? printf("1") : printf("0");
);
printf( " \n");
);

Results:

11111111111100000000000000000000
00000000000000000000000000000000
00000000000011111111000000000000
00000000000000000000000000000000

Any tips on what I'm missing?

James Slanger
06-22-2018, 02:38 PM
XOR'ing with FULL_MASK works, but is this the best way to invert a mask in EEL?

mschnell
06-26-2018, 08:10 AM
For 32 bit operations you have the standard C operators.

If you want to use more bits, you need to do + and - with constants that you previously defined. This might be rater tricky.

-Michael

James Slanger
06-27-2018, 12:32 PM
For 32 bit operations you have the standard C operators.

But not all the C operators correct? Shouldn't ~ do a bit-wise NOT then?
inverted = ~COLOR_MASK; // generates a syntax error

-Jim

EDIT: Still wrapping my brain around what is available via C vs EEL2 in OSCii-bot. My understanding is that everything is either a double-float or string. Yet match() includes format specifiers for unsigned, etc? Can I cast variables to unsigned?

mschnell
06-27-2018, 02:30 PM
c = a ~ b; and c ~= b; do compile.

In format type functions the float values are internally converted to integers etc if the specifier requests this.

(Same happens for array indexes, of course.)

-Michael

James Slanger
06-27-2018, 04:40 PM
But just to confirm: there is no unary bitwise NOT operator in EEL?

mschnell
06-27-2018, 09:28 PM
Seems like being forgotten. Seemingly you need to do \$xFFFFFFFF ~ a instead. Maybe do a not() function

(...or implement it, as OSCII-Bot is open source :) )

Anyway, you should use constants for the positive and negative masks, constructed in @init.

-Michael