Skip to content

Use unordered_map instead of vector for primitives#384

Draft
MaartenS11 wants to merge 1 commit into
mainfrom
feat/primitive-map
Draft

Use unordered_map instead of vector for primitives#384
MaartenS11 wants to merge 1 commit into
mainfrom
feat/primitive-map

Conversation

@MaartenS11

@MaartenS11 MaartenS11 commented Jun 12, 2026

Copy link
Copy Markdown
Member

Technically this should be faster than a linear search + it allows overwriting primitives that you already have. For example:

wac->interpreter->register_primitive("chip_digital_write", [](Module *m) -> bool {
    pop_args(2);
    printf("custom chip_digital_write behaviour!\n");
    return true;
}, &twoToNoneU32);

This overwriting is particularly useful for the concolic version of the interpreter so that it can have custom implementations that for example push symbolic variables.

Size difference

Size increase by 688 bytes
After change:

Memory region         Used Size  Region Size  %age Used
           FLASH:      292128 B    4194048 B      6.97%
     iram0_0_seg:       39680 B       224 KB     17.30%
     dram0_0_seg:       29872 B       192 KB     15.19%
     dram1_0_seg:         14 KB        96 KB     14.58%
     irom0_0_seg:      161056 B     11456 KB      1.37%
     drom0_0_seg:         64 KB         4 MB      1.56%
    rtc_iram_seg:           0 B         8 KB      0.00%
    rtc_slow_seg:          40 B         8 KB      0.49%
    rtc_data_seg:           0 B         8 KB      0.00%
        IDT_LIST:           0 B         8 KB      0.00%

Current main branch:

Memory region         Used Size  Region Size  %age Used
           FLASH:      291440 B    4194048 B      6.95%
     iram0_0_seg:       39680 B       224 KB     17.30%
     dram0_0_seg:       29736 B       192 KB     15.12%
     dram1_0_seg:         14 KB        96 KB     14.58%
     irom0_0_seg:      160368 B     11456 KB      1.37%
     drom0_0_seg:         64 KB         4 MB      1.56%
    rtc_iram_seg:           0 B         8 KB      0.00%
    rtc_slow_seg:          40 B         8 KB      0.49%
    rtc_data_seg:           0 B         8 KB      0.00%
        IDT_LIST:           0 B         8 KB      0.00%

Technically this should be faster than a linear search + it allows overwriting primitives that you already have. For example:
```cpp
wac->interpreter->register_primitive("chip_digital_write", [](Module *m) -> bool {
    pop_args(2);
    printf("chip_digital_write\n");
    return true;
}, &twoToNoneU32);
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant