diff options
author | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2017-03-22 11:54:01 +0100 |
---|---|---|
committer | Hanspeter Portner <dev@open-music-kontrollers.ch> | 2017-03-22 11:54:01 +0100 |
commit | 52abc1ad3a4d0226e1d8a5a3d8bc63bf7dc67a31 (patch) | |
tree | f3990b8e1e1da59fd4075c54a2b0c7e7d44dbbfc | |
parent | a1d39643fd1826af7feb25d5198ee9c144e1d449 (diff) | |
download | vm.lv2-52abc1ad3a4d0226e1d8a5a3d8bc63bf7dc67a31.tar.xz |
reorder opcodes.
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | vm.c | 103 | ||||
-rw-r--r-- | vm.h | 147 |
3 files changed, 138 insertions, 114 deletions
@@ -1 +1 @@ -0.1.2861 +0.1.2863 @@ -355,6 +355,33 @@ run(LV2_Handle instance, uint32_t nsamples) const num_t c = _stack_peek(&handle->stack); _stack_push(&handle->stack, c); } break; + case OP_SWAP: + { + num_t ab [2]; + _stack_pop_num(&handle->stack, ab, 2); + _stack_push_num(&handle->stack, ab, 2); + } break; + case OP_STORE: + { + num_t ab [2]; + _stack_pop_num(&handle->stack, ab, 2); + const int idx = floorf(ab[0]); + handle->stack.regs[idx & REG_MASK] = ab[1]; + } break; + case OP_LOAD: + { + const num_t a = _stack_pop(&handle->stack); + const int idx = floorf(a); + const num_t c = handle->stack.regs[idx & REG_MASK]; + _stack_push(&handle->stack, c); + } break; + + case OP_RAND: + { + const num_t c = (num_t)rand() / RAND_MAX; + _stack_push(&handle->stack, c); + } break; + case OP_ADD: { num_t ab [2]; @@ -385,6 +412,23 @@ run(LV2_Handle instance, uint32_t nsamples) : ab[1] / ab[0]; _stack_push(&handle->stack, c); } break; + case OP_MOD: + { + num_t ab [2]; + _stack_pop_num(&handle->stack, ab, 2); + const num_t c = ab[0] == 0.0 + ? 0.0 + : fmod(ab[1], ab[0]); + _stack_push(&handle->stack, c); + } break; + case OP_POW: + { + num_t ab [2]; + _stack_pop_num(&handle->stack, ab, 2); + const num_t c = pow(ab[1], ab[0]); + _stack_push(&handle->stack, c); + } break; + case OP_NEG: { const num_t a = _stack_pop(&handle->stack); @@ -397,28 +441,13 @@ run(LV2_Handle instance, uint32_t nsamples) const num_t c = fabs(a); _stack_push(&handle->stack, c); } break; - case OP_POW: - { - num_t ab [2]; - _stack_pop_num(&handle->stack, ab, 2); - const num_t c = pow(ab[1], ab[0]); - _stack_push(&handle->stack, c); - } break; case OP_SQRT: { const num_t a = _stack_pop(&handle->stack); const num_t c = sqrt(a); _stack_push(&handle->stack, c); } break; - case OP_MOD: - { - num_t ab [2]; - _stack_pop_num(&handle->stack, ab, 2); - const num_t c = ab[0] == 0.0 - ? 0.0 - : fmod(ab[1], ab[0]); - _stack_push(&handle->stack, c); - } break; + case OP_EXP: { const num_t a = _stack_pop(&handle->stack); @@ -449,6 +478,7 @@ run(LV2_Handle instance, uint32_t nsamples) const num_t c = log10(a); _stack_push(&handle->stack, c); } break; + case OP_SIN: { const num_t a = _stack_pop(&handle->stack); @@ -461,17 +491,12 @@ run(LV2_Handle instance, uint32_t nsamples) const num_t c = cos(a); _stack_push(&handle->stack, c); } break; - case OP_SWAP: - { - num_t ab [2]; - _stack_pop_num(&handle->stack, ab, 2); - _stack_push_num(&handle->stack, ab, 2); - } break; case OP_PI: { num_t c = M_PI; _stack_push(&handle->stack, c); } break; + case OP_EQ: { num_t ab [2]; @@ -507,6 +532,14 @@ run(LV2_Handle instance, uint32_t nsamples) const bool c = ab[1] >= ab[0]; _stack_push(&handle->stack, c); } break; + case OP_TER: + { + num_t ab [3]; + _stack_pop_num(&handle->stack, ab, 3); + const bool c = ab[0]; + _stack_push(&handle->stack, c ? ab[2] : ab[1]); + } break; + case OP_AND: { num_t ab [2]; @@ -569,32 +602,6 @@ run(LV2_Handle instance, uint32_t nsamples) const unsigned c = a >> b; _stack_push(&handle->stack, c); } break; - case OP_TER: - { - num_t ab [3]; - _stack_pop_num(&handle->stack, ab, 3); - const bool c = ab[0]; - _stack_push(&handle->stack, c ? ab[2] : ab[1]); - } break; - case OP_STORE: - { - num_t ab [2]; - _stack_pop_num(&handle->stack, ab, 2); - const int idx = floorf(ab[0]); - handle->stack.regs[idx & REG_MASK] = ab[1]; - } break; - case OP_LOAD: - { - const num_t a = _stack_pop(&handle->stack); - const int idx = floorf(a); - const num_t c = handle->stack.regs[idx & REG_MASK]; - _stack_push(&handle->stack, c); - } break; - case OP_RAND: - { - const num_t c = (num_t)rand() / RAND_MAX; - _stack_push(&handle->stack, c); - } break; // time case OP_BAR_BEAT: @@ -77,41 +77,50 @@ enum _vm_opcode_enum_t { OP_CTRL, OP_PUSH, + OP_SWAP, + OP_STORE, + OP_LOAD, + + OP_RAND, + OP_ADD, OP_SUB, OP_MUL, OP_DIV, + OP_MOD, + OP_POW, + OP_NEG, OP_ABS, - OP_POW, OP_SQRT, - OP_MOD, + OP_EXP, OP_EXP_2, OP_LOG, OP_LOG_2, OP_LOG_10, + OP_SIN, OP_COS, - OP_SWAP, OP_PI, + OP_EQ, OP_LT, OP_GT, OP_LE, OP_GE, + OP_TER, + OP_AND, OP_OR, OP_NOT, + OP_BAND, OP_BOR, OP_BNOT, OP_LSHIFT, OP_RSHIFT, - OP_TER, - OP_STORE, - OP_LOAD, - OP_RAND, + OP_BAR_BEAT, OP_BAR, OP_BEAT, @@ -141,9 +150,7 @@ struct _vm_command_t { union { int32_t i32; - int64_t i64; float f32; - double f64; vm_opcode_enum_t op; }; }; @@ -165,11 +172,11 @@ struct _plugstate_t { }; static const char *command_labels [COMMAND_MAX] = { - [COMMAND_NOP] = "", - [COMMAND_OPCODE] = "Op Code" , - [COMMAND_BOOL] = "Boolean" , - [COMMAND_INT] = "Integer" , - [COMMAND_FLOAT] = "Float" , + [COMMAND_NOP] = "", + [COMMAND_OPCODE] = "Op Code", + [COMMAND_BOOL] = "Boolean", + [COMMAND_INT] = "Integer", + [COMMAND_FLOAT] = "Float", }; static const vm_api_def_t vm_api_def [OP_MAX] = { @@ -180,6 +187,7 @@ static const vm_api_def_t vm_api_def [OP_MAX] = { .npops = 0, .npushs = 0 }, + [OP_CTRL] = { .uri = VM_PREFIX"opInput", .label = "input", @@ -194,6 +202,36 @@ static const vm_api_def_t vm_api_def [OP_MAX] = { .npops = 1, .npushs = 2 }, + [OP_SWAP] = { + .uri = VM_PREFIX"opSwap", + .label = "Swap", + .mnemo = "swap", + .npops = 2, + .npushs = 2 + }, + [OP_STORE] = { + .uri = VM_PREFIX"opStore", + .label = "Store in register", + .mnemo = "store", + .npops = 2, + .npushs = 0 + }, + [OP_LOAD] = { + .uri = VM_PREFIX"opLoad", + .label = "Load from register", + .mnemo = "load", + .npops = 1, + .npushs = 1 + }, + + [OP_RAND] = { + .uri = VM_PREFIX"opRand", + .label = "Random number", + .mnemo = "rand", + .npops = 0, + .npushs = 1 + }, + [OP_ADD] = { .uri = VM_PREFIX"opAdd", .label = "Add", @@ -222,6 +260,21 @@ static const vm_api_def_t vm_api_def [OP_MAX] = { .npops = 2, .npushs = 1 }, + [OP_MOD] = { + .uri = VM_PREFIX"opMod", + .label = "Modulo", + .mnemo = "%", + .npops = 2, + .npushs = 1 + }, + [OP_POW] = { + .uri = VM_PREFIX"opPow", + .label = "Power", + .mnemo = "^", + .npops = 2, + .npushs = 1 + }, + [OP_NEG] = { .uri = VM_PREFIX"opNeg", .label = "Negate", @@ -236,13 +289,6 @@ static const vm_api_def_t vm_api_def [OP_MAX] = { .npops = 1, .npushs = 1 }, - [OP_POW] = { - .uri = VM_PREFIX"opPow", - .label = "Power", - .mnemo = "^", - .npops = 2, - .npushs = 1 - }, [OP_SQRT] = { .uri = VM_PREFIX"opSqrt", .label = "Square root", @@ -250,13 +296,7 @@ static const vm_api_def_t vm_api_def [OP_MAX] = { .npops = 1, .npushs = 1 }, - [OP_MOD] = { - .uri = VM_PREFIX"opMod", - .label = "Modulo", - .mnemo = "%", - .npops = 2, - .npushs = 1 - }, + [OP_EXP] = { .uri = VM_PREFIX"opExp", .label = "Exponential", @@ -292,6 +332,7 @@ static const vm_api_def_t vm_api_def [OP_MAX] = { .npops = 1, .npushs = 1 }, + [OP_SIN] = { .uri = VM_PREFIX"opSin", .label = "Sinus", @@ -306,13 +347,6 @@ static const vm_api_def_t vm_api_def [OP_MAX] = { .npops = 1, .npushs = 1 }, - [OP_SWAP] = { - .uri = VM_PREFIX"opSwap", - .label = "Swap", - .mnemo = "swap", - .npops = 2, - .npushs = 2 - }, [OP_PI] = { .uri = VM_PREFIX"opPi", .label = "Pi", @@ -320,6 +354,7 @@ static const vm_api_def_t vm_api_def [OP_MAX] = { .npops = 0, .npushs = 1 }, + [OP_EQ] = { .uri = VM_PREFIX"opEq", .label = "Equal", @@ -355,6 +390,14 @@ static const vm_api_def_t vm_api_def [OP_MAX] = { .npops = 2, .npushs = 1 }, + [OP_TER] = { + .uri = VM_PREFIX"opTernary", + .label = "Ternary operator", + .mnemo = "?", + .npops = 3, + .npushs = 1 + }, + [OP_AND] = { .uri = VM_PREFIX"opAnd", .label = "And", @@ -376,6 +419,7 @@ static const vm_api_def_t vm_api_def [OP_MAX] = { .npops = 1, .npushs = 1 }, + [OP_BAND] = { .uri = VM_PREFIX"opBAnd", .label = "Bitwise and", @@ -411,34 +455,7 @@ static const vm_api_def_t vm_api_def [OP_MAX] = { .npops = 2, .npushs = 1 }, - [OP_TER] = { - .uri = VM_PREFIX"opTernary", - .label = "Ternary operator", - .mnemo = "?", - .npops = 3, - .npushs = 1 - }, - [OP_STORE] = { - .uri = VM_PREFIX"opStore", - .label = "Store in register", - .mnemo = "store", - .npops = 2, - .npushs = 0 - }, - [OP_LOAD] = { - .uri = VM_PREFIX"opLoad", - .label = "Load from register", - .mnemo = "load", - .npops = 1, - .npushs = 1 - }, - [OP_RAND] = { - .uri = VM_PREFIX"opRand", - .label = "Random number", - .mnemo = "rand", - .npops = 0, - .npushs = 1 - }, + [OP_BAR_BEAT] = { .uri = LV2_TIME__barBeat, .label = "time:barBeat", @@ -609,7 +626,7 @@ vm_deserialize(vm_api_impl_t *impl, LV2_Atom_Forge *forge, else if(item->type == forge->Long) { cmd->type = COMMAND_INT; - cmd->i64 = ((const LV2_Atom_Long *)item)->body; + cmd->i32 = ((const LV2_Atom_Long *)item)->body; } else if(item->type == forge->Float) { @@ -619,7 +636,7 @@ vm_deserialize(vm_api_impl_t *impl, LV2_Atom_Forge *forge, else if(item->type == forge->Double) { cmd->type = COMMAND_FLOAT; - cmd->f64 = ((const LV2_Atom_Double *)item)->body; + cmd->f32 = ((const LV2_Atom_Double *)item)->body; } else if(item->type == forge->URID) { |