separate mask digit count

This commit is contained in:
Aliaksei Chapyzhenka 2022-05-31 18:30:32 -07:00
parent d6894b5831
commit df569a6b77
11 changed files with 97 additions and 62 deletions

View File

@ -36,6 +36,7 @@ const properties = {
value: 'ptr', // value of the signal on change event value: 'ptr', // value of the signal on change event
mask: 'ptr', // mask (x, z) of the signal on change event mask: 'ptr', // mask (x, z) of the signal on change event
digitCount: 'i32', digitCount: 'i32',
maskCount: 'i32',
tmpStr: 'ptr', tmpStr: 'ptr',
timeStampStr: 'ptr', timeStampStr: 'ptr',
idStr: 'ptr', idStr: 'ptr',

View File

@ -24,8 +24,11 @@ const dotProp = require('dot-prop');
// } // }
function h8ToBn(HEAPU8, start, len) { function h8ToBn(HEAPU8, start, len) {
if (len === 0) {
return 0n;
}
let str = ''; let str = '';
const fin = start + len; const fin = start + len * 8;
for (let i = start; i < fin; i++) { for (let i = start; i < fin; i++) {
const val = HEAPU8[i]; const val = HEAPU8[i];
str = val.toString(16) + str; str = val.toString(16) + str;
@ -97,6 +100,39 @@ const getWrapper = wasm => {
let context = -1; let context = -1;
const onEE1 = (
/* const char* */ eventName,
/* const size_t */ eventNameLength, // strlen(name)
/* const int64_t */ time,
/* const int */ cmd,
/* const int */ valueWords,
/* uint64_t* */ value,
/* const int */ maskWords,
/* uint64_t* */ mask
) => {
const name = getString(eventName, eventNameLength);
// console.log(`event name`);
// console.log({name, time, command, valueWords});
// const view0 = wasm.HEAPU8.subarray(value, value+(valueWords*8));
// const view1 = wasm.HEAPU8.subarray(mask, mask+(valueWords*8));
// let bigValue = u8ToBn(view0);
// let bigMask = u8ToBn(view1);
// let bigValue = 0n;
// console.log(bigValue.toString(16));
if (cmd >= 14 && cmd <= 28) {
ee[1](name, time, cmd);
} else {
const bigValue = h8ToBn(wasm.HEAPU8, value, valueWords);
const bigMask = h8ToBn(wasm.HEAPU8, mask, maskWords);
ee[1](name, time, cmd, bigValue, bigMask);
}
};
// wasm.addFunction can't be called until after // wasm.addFunction can't be called until after
// start finishes // start finishes
bindCallback = () => { bindCallback = () => {
@ -150,27 +186,7 @@ const getWrapper = wasm => {
ee[0](getString(name, len)); ee[0](getString(name, len));
}, 'vii'); }, 'vii');
// const char* name, const size_t len, const uint64_t time, const uint8_t command, const int valueWords, const uint64_t* aValue, const uint64_t* aMask); boundEE1 = wasm.addFunction(onEE1, 'viijiiiii');
// boundEE1 = wasm.addFunction(function(eventName, l0, time, command, valueWords, value, mask) {
boundEE1 = wasm.addFunction(function(eventName, l0, time, command, valueWords, value, mask) {
const name = getString(eventName, l0);
// console.log(`event name`);
// console.log({name, time, command, valueWords});
// const view0 = wasm.HEAPU8.subarray(value, value+(valueWords*8));
// const view1 = wasm.HEAPU8.subarray(mask, mask+(valueWords*8));
// let bigValue = u8ToBn(view0);
// let bigMask = u8ToBn(view1);
// let bigValue = 0n;
// console.log(bigValue.toString(16));
const bigValue = h8ToBn(wasm.HEAPU8, value, valueWords * 8);
const bigMask = h8ToBn(wasm.HEAPU8, mask, valueWords * 8);
ee[1](name, time, command, bigValue, bigMask);
}, 'viijiiii');
}; };

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ const chopper = require('../lib/chopper.js');
const expectaitions = [ const expectaitions = [
{ id: '"}G', time: 100n, cmd: 14, value: 0n, mask: 0n }, { id: '"}G', time: 100n, cmd: 14, value: 0n, mask: 0n },
{ id: '"}G', time: 200n, cmd: 15, value: 1n, mask: 0n }, { id: '"}G', time: 200n, cmd: 15, value: 0n, mask: 0n },
{ id: '{u', time: 200n, cmd: 30, value: 0xf0f0f0f0f0f0f0f0n, mask: 0xff00ff00ff00ff00n }, { id: '{u', time: 200n, cmd: 30, value: 0xf0f0f0f0f0f0f0f0n, mask: 0xff00ff00ff00ff00n },
{ id: '"}G', time: 300n, cmd: 14, value: 0n, mask: 0n }, { id: '"}G', time: 300n, cmd: 14, value: 0n, mask: 0n },
{ id: '{u', time: 300n, cmd: 30, value: 0xf000000000000000n, mask: 0n }, { id: '{u', time: 300n, cmd: 30, value: 0xf000000000000000n, mask: 0n },
@ -44,7 +44,7 @@ const expectaitions = [
{ id: 'u)', time: 314n, cmd: 30, value: 14n, mask: 0n }, { id: 'u)', time: 314n, cmd: 30, value: 14n, mask: 0n },
{ id: '{u', time: 315n, cmd: 30, value: 0x000000000000000fn, mask: 0n }, { id: '{u', time: 315n, cmd: 30, value: 0x000000000000000fn, mask: 0n },
{ id: 'u)', time: 315n, cmd: 30, value: 15n, mask: 0n }, { id: 'u)', time: 315n, cmd: 30, value: 15n, mask: 0n },
{ id: '"}G', time: 316n, cmd: 15, value: 1n, mask: 0n } { id: '"}G', time: 316n, cmd: 15, value: 0n, mask: 0n }
]; ];
describe('napi dump', function () { describe('napi dump', function () {

File diff suppressed because one or more lines are too long

View File

@ -9,10 +9,10 @@ const webVcdParser = require('../lib/web-vcd-parser.js');
const chopper = require('../lib/chopper.js'); const chopper = require('../lib/chopper.js');
const expectaitions = [ const expectaitions = [
{ id: '"}G', time: 100n, cmd: 14, value: 0n, mask: 0n }, { id: '"}G', time: 100n, cmd: 14, value: undefined, mask: undefined },
{ id: '"}G', time: 200n, cmd: 15, value: 1n, mask: 0n }, { id: '"}G', time: 200n, cmd: 15, value: undefined, mask: undefined },
{ id: '{u', time: 200n, cmd: 30, value: 0xf0f0f0f0f0f0f0f0n, mask: 0xff00ff00ff00ff00n }, { id: '{u', time: 200n, cmd: 30, value: 0xf0f0f0f0f0f0f0f0n, mask: 0xff00ff00ff00ff00n },
{ id: '"}G', time: 300n, cmd: 14, value: 0n, mask: 0n }, { id: '"}G', time: 300n, cmd: 14, value: undefined, mask: undefined },
{ id: '{u', time: 300n, cmd: 30, value: 0xf000000000000000n, mask: 0n }, { id: '{u', time: 300n, cmd: 30, value: 0xf000000000000000n, mask: 0n },
{ id: 'u)', time: 300n, cmd: 30, value: 0n, mask: 0n }, { id: 'u)', time: 300n, cmd: 30, value: 0n, mask: 0n },
{ id: '{u', time: 301n, cmd: 30, value: 0x0f00000000000000n, mask: 0n }, { id: '{u', time: 301n, cmd: 30, value: 0x0f00000000000000n, mask: 0n },
@ -45,7 +45,7 @@ const expectaitions = [
{ id: 'u)', time: 314n, cmd: 30, value: 14n, mask: 0n }, { id: 'u)', time: 314n, cmd: 30, value: 14n, mask: 0n },
{ id: '{u', time: 315n, cmd: 30, value: 0x000000000000000fn, mask: 0n }, { id: '{u', time: 315n, cmd: 30, value: 0x000000000000000fn, mask: 0n },
{ id: 'u)', time: 315n, cmd: 30, value: 15n, mask: 0n }, { id: 'u)', time: 315n, cmd: 30, value: 15n, mask: 0n },
{ id: '"}G', time: 316n, cmd: 15, value: 1n, mask: 0n } { id: '"}G', time: 316n, cmd: 15, value: undefined, mask: undefined }
]; ];
describe('wasm dump', () => { describe('wasm dump', () => {

1
vcd.c
View File

@ -142,6 +142,7 @@ METHOD(init) {
state->mask = maskBuf; state->mask = maskBuf;
state->time = INT64_MAX; state->time = INT64_MAX;
state->digitCount = 0; state->digitCount = 0;
state->maskCount = 0;
napi_value status; napi_value status;
ASSERT(status, napi_create_string_latin1(env, "declaration", NAPI_AUTO_LENGTH, &status)) ASSERT(status, napi_create_string_latin1(env, "declaration", NAPI_AUTO_LENGTH, &status))

View File

@ -220,20 +220,21 @@ int onId (vcd_parser_t* state, const unsigned char* _p, const unsigned char* _en
const unsigned char* endp = p + plen - 1; const unsigned char* endp = p + plen - 1;
// printf("<onId|%s>\n", (char *)state->idStr); // printf("<onId|%s>\n", (char *)state->idStr);
const int valueWords = (state->digitCount >> 6) + 1; const int valueWords = (state->digitCount + 63) >> 6;
const int maskWords = (state->maskCount + 63) >> 6;
uint64_t* value = state->value; uint64_t* value = state->value;
uint64_t* mask = state->mask; uint64_t* mask = state->mask;
if (stringEq((state->trigger), p, endp)) { if (stringEq((state->trigger), p, endp)) {
const uint8_t command = state->command; const uint8_t command = state->command;
// printf("{id:'%s',cmd:%d}", (char *)p, command); // printf("{id:'%s',cmd:%d}", (char *)p, command);
if (command == 14) { // if (command == 14) {
value[0] = 0; // value[0] = 0;
mask[0] = 0; // mask[0] = 0;
} else // } else
if (command == 15) { // if (command == 15) {
value[0] = 1; // value[0] = 1;
mask[0] = 0; // mask[0] = 0;
} // }
#ifndef VCDWASM #ifndef VCDWASM
napi_value undefined, eventName, aTime, aCommand, aValue, aMask, return_val; napi_value undefined, eventName, aTime, aCommand, aValue, aMask, return_val;
ASSERT(undefined, napi_get_undefined(env, &undefined)) ASSERT(undefined, napi_get_undefined(env, &undefined))
@ -241,20 +242,23 @@ int onId (vcd_parser_t* state, const unsigned char* _p, const unsigned char* _en
ASSERT(aTime, napi_create_int64(env, state->time, &aTime)) ASSERT(aTime, napi_create_int64(env, state->time, &aTime))
ASSERT(aCommand, napi_create_int32(env, command, &aCommand)) ASSERT(aCommand, napi_create_int32(env, command, &aCommand))
ASSERT(aValue, napi_create_bigint_words(env, 0, valueWords, value, &aValue)) ASSERT(aValue, napi_create_bigint_words(env, 0, valueWords, value, &aValue))
ASSERT(aMask, napi_create_bigint_words(env, 0, valueWords, mask, &aMask)) ASSERT(aMask, napi_create_bigint_words(env, 0, maskWords, mask, &aMask))
napi_value* argv[] = {&eventName, &aTime, &aCommand, &aValue, &aMask}; napi_value* argv[] = {&eventName, &aTime, &aCommand, &aValue, &aMask};
ASSERT(state->triee, napi_call_function(env, undefined, state->triee, 5, *argv, &return_val)) ASSERT(state->triee, napi_call_function(env, undefined, state->triee, 5, *argv, &return_val))
// printf("<id='%s'>", (char *)p); // printf("<id='%s'>", (char *)p);
#else #else
// strcopy(p, endp, state->tmpStr); // strcopy(p, endp, state->tmpStr);
emit_triee((char *)p, state->time, command, valueWords, value, mask); emit_triee((char *)p, state->time, command, valueWords, value, maskWords, mask);
#endif #endif
} }
for (int i = 0; i < valueWords; i++) { for (int i = 0; i < valueWords; i++) {
value[i] = 0; value[i] = 0;
}
for (int i = 0; i < maskWords; i++) {
mask[i] = 0; mask[i] = 0;
} }
state->digitCount = 0; state->digitCount = 0;
state->maskCount = 0;
*(char *)state->idStr = 0; *(char *)state->idStr = 0;
return 0; return 0;
} }
@ -263,29 +267,36 @@ int onId (vcd_parser_t* state, const unsigned char* _p, const unsigned char* _en
int onDigit( int onDigit(
vcd_parser_t* state, vcd_parser_t* state,
const unsigned char* p, const unsigned char* _p,
const unsigned char* endp, const unsigned char* _endp,
int digit int digit
) { ) {
unsigned int valueCin = (digit & 1); unsigned int valueCin = (digit & 1);
unsigned int maskCin = ((digit >> 1) & 1); unsigned int maskCin = ((digit >> 1) & 1);
if ((valueCin != 0) || (state->digitCount != 0)) {
unsigned int valueCout; unsigned int valueCout;
unsigned int maskCout;
uint64_t* value = state->value; uint64_t* value = state->value;
uint64_t* mask = state->mask;
const int valueWordsMinus = (state->digitCount >> 6); const int valueWordsMinus = (state->digitCount >> 6);
for (int i = 0; i <= valueWordsMinus; i++) { for (int i = 0; i <= valueWordsMinus; i++) {
valueCout = value[i] >> 63; valueCout = value[i] >> 63;
value[i] = (value[i] << 1) + valueCin; value[i] = (value[i] << 1) + valueCin;
valueCin = valueCout; valueCin = valueCout;
}
state->digitCount += 1;
}
if ((maskCin != 0) || (state->maskCount != 0)) {
unsigned int maskCout;
uint64_t* mask = state->mask;
const int maskWordsMinus = (state->maskCount >> 6);
for (int i = 0; i <= maskWordsMinus; i++) {
maskCout = mask[i] >> 63; maskCout = mask[i] >> 63;
mask[i] = (mask[i] << 1) + maskCin; mask[i] = (mask[i] << 1) + maskCin;
maskCin = maskCout; maskCin = maskCout;
} }
state->digitCount += 1; state->maskCount += 1;
}
return 0; return 0;
} }
@ -296,6 +307,7 @@ int onRecover(
int digit int digit
) { ) {
state->digitCount = 0; state->digitCount = 0;
state->maskCount = 0;
return 0; return 0;
} }

View File

@ -20,6 +20,7 @@ typedef void externalJsMethodOne (
const int command, const int command,
const int valueWords, const int valueWords,
const int aValue, const int aValue,
const int maskWords,
const int aMask const int aMask
); );
@ -71,6 +72,7 @@ void emit_triee(
const int command, const int command,
const int valueWords, const int valueWords,
uint64_t* aValue, uint64_t* aValue,
const int maskWords,
uint64_t* aMask uint64_t* aMask
) { ) {
@ -91,6 +93,7 @@ void emit_triee(
command, command,
valueWords, valueWords,
(int)aValue, (int)aValue,
maskWords,
(int)aMask (int)aMask
); );
} }
@ -142,6 +145,7 @@ int init(
state->mask = maskBuf; state->mask = maskBuf;
state->time = INT64_MAX; state->time = INT64_MAX;
state->digitCount = 0; state->digitCount = 0;
state->maskCount = 0;
set_property_string("status", "declaration"); set_property_string("status", "declaration");

View File

@ -14,5 +14,6 @@ void emit_triee(
const int command, const int command,
const int valueWords, const int valueWords,
uint64_t* aValue, uint64_t* aValue,
const int maskWords,
uint64_t* aMask uint64_t* aMask
); );