Skip to content

Commit df569a6

Browse files
committed
separate mask digit count
1 parent d6894b5 commit df569a6

11 files changed

+97
-62
lines changed

bin/build.js

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const properties = {
3636
value: 'ptr', // value of the signal on change event
3737
mask: 'ptr', // mask (x, z) of the signal on change event
3838
digitCount: 'i32',
39+
maskCount: 'i32',
3940
tmpStr: 'ptr',
4041
timeStampStr: 'ptr',
4142
idStr: 'ptr',

lib/web-vcd-parser.js

+38-22
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ const dotProp = require('dot-prop');
2424
// }
2525

2626
function h8ToBn(HEAPU8, start, len) {
27+
if (len === 0) {
28+
return 0n;
29+
}
2730
let str = '';
28-
const fin = start + len;
31+
const fin = start + len * 8;
2932
for (let i = start; i < fin; i++) {
3033
const val = HEAPU8[i];
3134
str = val.toString(16) + str;
@@ -97,6 +100,39 @@ const getWrapper = wasm => {
97100
let context = -1;
98101

99102

103+
const onEE1 = (
104+
/* const char* */ eventName,
105+
/* const size_t */ eventNameLength, // strlen(name)
106+
/* const int64_t */ time,
107+
/* const int */ cmd,
108+
/* const int */ valueWords,
109+
/* uint64_t* */ value,
110+
/* const int */ maskWords,
111+
/* uint64_t* */ mask
112+
) => {
113+
const name = getString(eventName, eventNameLength);
114+
// console.log(`event name`);
115+
// console.log({name, time, command, valueWords});
116+
117+
118+
// const view0 = wasm.HEAPU8.subarray(value, value+(valueWords*8));
119+
// const view1 = wasm.HEAPU8.subarray(mask, mask+(valueWords*8));
120+
121+
// let bigValue = u8ToBn(view0);
122+
// let bigMask = u8ToBn(view1);
123+
// let bigValue = 0n;
124+
125+
// console.log(bigValue.toString(16));
126+
127+
if (cmd >= 14 && cmd <= 28) {
128+
ee[1](name, time, cmd);
129+
} else {
130+
const bigValue = h8ToBn(wasm.HEAPU8, value, valueWords);
131+
const bigMask = h8ToBn(wasm.HEAPU8, mask, maskWords);
132+
ee[1](name, time, cmd, bigValue, bigMask);
133+
}
134+
};
135+
100136
// wasm.addFunction can't be called until after
101137
// start finishes
102138
bindCallback = () => {
@@ -150,27 +186,7 @@ const getWrapper = wasm => {
150186
ee[0](getString(name, len));
151187
}, 'vii');
152188

153-
// 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);
154-
// boundEE1 = wasm.addFunction(function(eventName, l0, time, command, valueWords, value, mask) {
155-
boundEE1 = wasm.addFunction(function(eventName, l0, time, command, valueWords, value, mask) {
156-
const name = getString(eventName, l0);
157-
// console.log(`event name`);
158-
// console.log({name, time, command, valueWords});
159-
160-
161-
// const view0 = wasm.HEAPU8.subarray(value, value+(valueWords*8));
162-
// const view1 = wasm.HEAPU8.subarray(mask, mask+(valueWords*8));
163-
164-
// let bigValue = u8ToBn(view0);
165-
// let bigMask = u8ToBn(view1);
166-
// let bigValue = 0n;
167-
168-
// console.log(bigValue.toString(16));
169-
const bigValue = h8ToBn(wasm.HEAPU8, value, valueWords * 8);
170-
const bigMask = h8ToBn(wasm.HEAPU8, mask, valueWords * 8);
171-
172-
ee[1](name, time, command, bigValue, bigMask);
173-
}, 'viijiiii');
189+
boundEE1 = wasm.addFunction(onEE1, 'viijiiiii');
174190

175191
};
176192

out/vcd.wasm

47 Bytes
Binary file not shown.

test/napi_any.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/napi_dump.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const chopper = require('../lib/chopper.js');
99

1010
const expectaitions = [
1111
{ id: '"}G', time: 100n, cmd: 14, value: 0n, mask: 0n },
12-
{ id: '"}G', time: 200n, cmd: 15, value: 1n, mask: 0n },
12+
{ id: '"}G', time: 200n, cmd: 15, value: 0n, mask: 0n },
1313
{ id: '{u', time: 200n, cmd: 30, value: 0xf0f0f0f0f0f0f0f0n, mask: 0xff00ff00ff00ff00n },
1414
{ id: '"}G', time: 300n, cmd: 14, value: 0n, mask: 0n },
1515
{ id: '{u', time: 300n, cmd: 30, value: 0xf000000000000000n, mask: 0n },
@@ -44,7 +44,7 @@ const expectaitions = [
4444
{ id: 'u)', time: 314n, cmd: 30, value: 14n, mask: 0n },
4545
{ id: '{u', time: 315n, cmd: 30, value: 0x000000000000000fn, mask: 0n },
4646
{ id: 'u)', time: 315n, cmd: 30, value: 15n, mask: 0n },
47-
{ id: '"}G', time: 316n, cmd: 15, value: 1n, mask: 0n }
47+
{ id: '"}G', time: 316n, cmd: 15, value: 0n, mask: 0n }
4848
];
4949

5050
describe('napi dump', function () {

test/wasm_any.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/wasm_dump.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ const webVcdParser = require('../lib/web-vcd-parser.js');
99
const chopper = require('../lib/chopper.js');
1010

1111
const expectaitions = [
12-
{ id: '"}G', time: 100n, cmd: 14, value: 0n, mask: 0n },
13-
{ id: '"}G', time: 200n, cmd: 15, value: 1n, mask: 0n },
12+
{ id: '"}G', time: 100n, cmd: 14, value: undefined, mask: undefined },
13+
{ id: '"}G', time: 200n, cmd: 15, value: undefined, mask: undefined },
1414
{ id: '{u', time: 200n, cmd: 30, value: 0xf0f0f0f0f0f0f0f0n, mask: 0xff00ff00ff00ff00n },
15-
{ id: '"}G', time: 300n, cmd: 14, value: 0n, mask: 0n },
15+
{ id: '"}G', time: 300n, cmd: 14, value: undefined, mask: undefined },
1616
{ id: '{u', time: 300n, cmd: 30, value: 0xf000000000000000n, mask: 0n },
1717
{ id: 'u)', time: 300n, cmd: 30, value: 0n, mask: 0n },
1818
{ id: '{u', time: 301n, cmd: 30, value: 0x0f00000000000000n, mask: 0n },
@@ -45,7 +45,7 @@ const expectaitions = [
4545
{ id: 'u)', time: 314n, cmd: 30, value: 14n, mask: 0n },
4646
{ id: '{u', time: 315n, cmd: 30, value: 0x000000000000000fn, mask: 0n },
4747
{ id: 'u)', time: 315n, cmd: 30, value: 15n, mask: 0n },
48-
{ id: '"}G', time: 316n, cmd: 15, value: 1n, mask: 0n }
48+
{ id: '"}G', time: 316n, cmd: 15, value: undefined, mask: undefined }
4949
];
5050

5151
describe('wasm dump', () => {

vcd.c

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ METHOD(init) {
142142
state->mask = maskBuf;
143143
state->time = INT64_MAX;
144144
state->digitCount = 0;
145+
state->maskCount = 0;
145146

146147
napi_value status;
147148
ASSERT(status, napi_create_string_latin1(env, "declaration", NAPI_AUTO_LENGTH, &status))

vcd_spans.c

+40-28
Original file line numberDiff line numberDiff line change
@@ -220,41 +220,45 @@ int onId (vcd_parser_t* state, const unsigned char* _p, const unsigned char* _en
220220
const unsigned char* endp = p + plen - 1;
221221
// printf("<onId|%s>\n", (char *)state->idStr);
222222

223-
const int valueWords = (state->digitCount >> 6) + 1;
223+
const int valueWords = (state->digitCount + 63) >> 6;
224+
const int maskWords = (state->maskCount + 63) >> 6;
224225
uint64_t* value = state->value;
225226
uint64_t* mask = state->mask;
226227
if (stringEq((state->trigger), p, endp)) {
227228
const uint8_t command = state->command;
228229
// printf("{id:'%s',cmd:%d}", (char *)p, command);
229-
if (command == 14) {
230-
value[0] = 0;
231-
mask[0] = 0;
232-
} else
233-
if (command == 15) {
234-
value[0] = 1;
235-
mask[0] = 0;
236-
}
230+
// if (command == 14) {
231+
// value[0] = 0;
232+
// mask[0] = 0;
233+
// } else
234+
// if (command == 15) {
235+
// value[0] = 1;
236+
// mask[0] = 0;
237+
// }
237238
#ifndef VCDWASM
238239
napi_value undefined, eventName, aTime, aCommand, aValue, aMask, return_val;
239240
ASSERT(undefined, napi_get_undefined(env, &undefined))
240241
ASSERT(eventName, napi_create_string_latin1(env, (char*)p, NAPI_AUTO_LENGTH, &eventName))
241242
ASSERT(aTime, napi_create_int64(env, state->time, &aTime))
242243
ASSERT(aCommand, napi_create_int32(env, command, &aCommand))
243244
ASSERT(aValue, napi_create_bigint_words(env, 0, valueWords, value, &aValue))
244-
ASSERT(aMask, napi_create_bigint_words(env, 0, valueWords, mask, &aMask))
245+
ASSERT(aMask, napi_create_bigint_words(env, 0, maskWords, mask, &aMask))
245246
napi_value* argv[] = {&eventName, &aTime, &aCommand, &aValue, &aMask};
246247
ASSERT(state->triee, napi_call_function(env, undefined, state->triee, 5, *argv, &return_val))
247248
// printf("<id='%s'>", (char *)p);
248249
#else
249250
// strcopy(p, endp, state->tmpStr);
250-
emit_triee((char *)p, state->time, command, valueWords, value, mask);
251+
emit_triee((char *)p, state->time, command, valueWords, value, maskWords, mask);
251252
#endif
252253
}
253254
for (int i = 0; i < valueWords; i++) {
254255
value[i] = 0;
256+
}
257+
for (int i = 0; i < maskWords; i++) {
255258
mask[i] = 0;
256259
}
257260
state->digitCount = 0;
261+
state->maskCount = 0;
258262
*(char *)state->idStr = 0;
259263
return 0;
260264
}
@@ -263,29 +267,36 @@ int onId (vcd_parser_t* state, const unsigned char* _p, const unsigned char* _en
263267

264268
int onDigit(
265269
vcd_parser_t* state,
266-
const unsigned char* p,
267-
const unsigned char* endp,
270+
const unsigned char* _p,
271+
const unsigned char* _endp,
268272
int digit
269273
) {
274+
270275
unsigned int valueCin = (digit & 1);
271276
unsigned int maskCin = ((digit >> 1) & 1);
272-
unsigned int valueCout;
273-
unsigned int maskCout;
274-
uint64_t* value = state->value;
275-
uint64_t* mask = state->mask;
276-
const int valueWordsMinus = (state->digitCount >> 6);
277-
for (int i = 0; i <= valueWordsMinus; i++) {
278-
279-
valueCout = value[i] >> 63;
280-
value[i] = (value[i] << 1) + valueCin;
281-
valueCin = valueCout;
282-
283-
maskCout = mask[i] >> 63;
284-
mask[i] = (mask[i] << 1) + maskCin;
285-
maskCin = maskCout;
286277

278+
if ((valueCin != 0) || (state->digitCount != 0)) {
279+
unsigned int valueCout;
280+
uint64_t* value = state->value;
281+
const int valueWordsMinus = (state->digitCount >> 6);
282+
for (int i = 0; i <= valueWordsMinus; i++) {
283+
valueCout = value[i] >> 63;
284+
value[i] = (value[i] << 1) + valueCin;
285+
valueCin = valueCout;
286+
}
287+
state->digitCount += 1;
288+
}
289+
if ((maskCin != 0) || (state->maskCount != 0)) {
290+
unsigned int maskCout;
291+
uint64_t* mask = state->mask;
292+
const int maskWordsMinus = (state->maskCount >> 6);
293+
for (int i = 0; i <= maskWordsMinus; i++) {
294+
maskCout = mask[i] >> 63;
295+
mask[i] = (mask[i] << 1) + maskCin;
296+
maskCin = maskCout;
297+
}
298+
state->maskCount += 1;
287299
}
288-
state->digitCount += 1;
289300
return 0;
290301
}
291302

@@ -296,6 +307,7 @@ int onRecover(
296307
int digit
297308
) {
298309
state->digitCount = 0;
310+
state->maskCount = 0;
299311
return 0;
300312
}
301313

wasm_main.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ typedef void externalJsMethodOne (
2020
const int command,
2121
const int valueWords,
2222
const int aValue,
23+
const int maskWords,
2324
const int aMask
2425
);
2526

@@ -71,6 +72,7 @@ void emit_triee(
7172
const int command,
7273
const int valueWords,
7374
uint64_t* aValue,
75+
const int maskWords,
7476
uint64_t* aMask
7577
) {
7678

@@ -91,6 +93,7 @@ void emit_triee(
9193
command,
9294
valueWords,
9395
(int)aValue,
96+
maskWords,
9497
(int)aMask
9598
);
9699
}
@@ -142,6 +145,7 @@ int init(
142145
state->mask = maskBuf;
143146
state->time = INT64_MAX;
144147
state->digitCount = 0;
148+
state->maskCount = 0;
145149

146150
set_property_string("status", "declaration");
147151

wasm_main.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ void emit_triee(
1414
const int command,
1515
const int valueWords,
1616
uint64_t* aValue,
17+
const int maskWords,
1718
uint64_t* aMask
1819
);

0 commit comments

Comments
 (0)