Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better C++ compatibility and fixes to conditional branch/switch handling #10

Merged
merged 7 commits into from
Nov 1, 2024
Prev Previous commit
Next Next commit
Fixed OpAny and OpAll (previous version only checked first component …
…of the input). Implemented OpCompositeInsert (Khronos compiler generates this is 'size optimization' mode). Also perform full 64-bit copy in OpCompositeConstruct, instead of 32-bit copy.
  • Loading branch information
mtehver committed Apr 21, 2022
commit cb02416708a644b9076627984b340e351ebcfb67
32 changes: 28 additions & 4 deletions src/opcode_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ void spvm_execute_OpCompositeConstruct(spvm_word word_count, spvm_state_t state)
for (spvm_word i = 0; i < state->results[id].member_count; i++) {
spvm_word index = SPVM_READ_WORD(state->code_current);
if (state->results[id].members[i].member_count == 0)
state->results[id].members[i].value.s = state->results[index].members[0].value.s;
state->results[id].members[i].value.u64 = state->results[index].members[0].value.u64;
else
spvm_member_memcpy(&state->results[id].members[i].members[0], &state->results[index].members[0], state->results[index].member_count);
}
Expand Down Expand Up @@ -1015,6 +1015,30 @@ void spvm_execute_OpCompositeExtract(spvm_word word_count, spvm_state_t state)

spvm_member_memcpy(state->results[id].members, result, memcount);
}
void spvm_execute_OpCompositeInsert(spvm_word word_count, spvm_state_t state)
{
SPVM_SKIP_WORD(state->code_current);
spvm_word id = SPVM_READ_WORD(state->code_current);
spvm_word object_id = SPVM_READ_WORD(state->code_current);
spvm_word value_id = SPVM_READ_WORD(state->code_current);

spvm_word index_count = word_count - 5;

spvm_member_memcpy(state->results[id].members, state->results[value_id].members, state->results[value_id].member_count);

spvm_word index = SPVM_READ_WORD(state->code_current);
spvm_member_t result = state->results[id].members + index;

while (index_count) {
index = SPVM_READ_WORD(state->code_current);

result = result->members + index;

index_count--;
}

spvm_member_memcpy(result, state->results[object_id].members, state->results[object_id].member_count);
}
void spvm_execute_OpCopyObject(spvm_word word_count, spvm_state_t state)
{
SPVM_SKIP_WORD(state->code_current);
Expand Down Expand Up @@ -1516,7 +1540,7 @@ void spvm_execute_OpAny(spvm_word word_count, spvm_state_t state)
spvm_word vec = SPVM_READ_WORD(state->code_current);

spvm_byte result = 0;
for (spvm_word i = 0; i < state->results[id].member_count; i++)
for (spvm_word i = 0; i < state->results[vec].member_count; i++)
if (state->results[vec].members[i].value.b)
result = 1;
state->results[id].members[0].value.b = result;
Expand All @@ -1528,7 +1552,7 @@ void spvm_execute_OpAll(spvm_word word_count, spvm_state_t state)
spvm_word vec = SPVM_READ_WORD(state->code_current);

spvm_byte result = 1;
for (spvm_word i = 0; i < state->results[id].member_count; i++)
for (spvm_word i = 0; i < state->results[vec].member_count; i++)
if (!state->results[vec].members[i].value.b)
result = 0;
state->results[id].members[0].value.b = result;
Expand Down Expand Up @@ -2126,7 +2150,7 @@ void _spvm_context_create_execute_table(spvm_context_t ctx)
ctx->opcode_execute[SpvOpVectorShuffle] = spvm_execute_OpVectorShuffle;
ctx->opcode_execute[SpvOpCompositeConstruct] = spvm_execute_OpCompositeConstruct;
ctx->opcode_execute[SpvOpCompositeExtract] = spvm_execute_OpCompositeExtract;
ctx->opcode_execute[SpvOpCompositeInsert] = NULL;
ctx->opcode_execute[SpvOpCompositeInsert] = spvm_execute_OpCompositeInsert;
ctx->opcode_execute[SpvOpCopyObject] = spvm_execute_OpCopyObject;
ctx->opcode_execute[SpvOpTranspose] = spvm_execute_OpTranspose;
ctx->opcode_execute[SpvOpCopyLogical] = NULL;
Expand Down