yencode 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/platform.cc CHANGED
@@ -17,7 +17,7 @@
17
17
  # endif
18
18
  # endif
19
19
  # endif
20
- bool cpu_supports_neon() {
20
+ bool RapidYenc::cpu_supports_neon() {
21
21
  # if defined(AT_HWCAP)
22
22
  # ifdef __FreeBSD__
23
23
  unsigned long supported;
@@ -95,7 +95,7 @@ static inline int _GET_XCR() {
95
95
  // }
96
96
 
97
97
 
98
- int cpu_supports_isa() {
98
+ int RapidYenc::cpu_supports_isa() {
99
99
  int flags[4];
100
100
  _cpuid1(flags);
101
101
  int ret = 0;
@@ -132,29 +132,30 @@ int cpu_supports_isa() {
132
132
  int cpuInfo[4];
133
133
  _cpuidX(cpuInfo, 7, 0);
134
134
  if((cpuInfo[1] & 0x128) == 0x128 && (ret & ISA_FEATURE_LZCNT)) { // BMI2 + AVX2 + BMI1
135
-
136
- // check AVX10
137
- int cpuInfo2[4];
138
- _cpuidX(cpuInfo2, 7, 1);
139
- if(cpuInfo2[3] & 0x80000) {
140
- _cpuidX(cpuInfo2, 0x24, 0);
141
- if((cpuInfo2[1] & 0xff) >= 1 && ( // minimum AVX10.1
135
+ if((xcr & 0xE0) == 0xE0) { // AVX512 XSTATE (also applies to AVX10)
136
+ // check AVX10
137
+ int cpuInfo2[4];
138
+ _cpuidX(cpuInfo2, 7, 1);
139
+ if(cpuInfo2[3] & 0x80000) {
140
+ _cpuidX(cpuInfo2, 0x24, 0);
141
+ if((cpuInfo2[1] & 0xff) >= 1 && ( // minimum AVX10.1
142
142
  #ifdef YENC_DISABLE_AVX256
143
- cpuInfo2[1] & 0x10000 // AVX10/128
143
+ cpuInfo2[1] & 0x10000 // AVX10/128
144
144
  #else
145
- cpuInfo2[1] & 0x20000 // AVX10/256
145
+ cpuInfo2[1] & 0x20000 // AVX10/256
146
146
  #endif
147
- )) {
148
- if(((xcr & 0xE0) == 0xE0) && (cpuInfo2[1] & 0x40000)) ret |= ISA_FEATURE_EVEX512;
149
- return ret | ISA_LEVEL_VBMI2;
147
+ )) {
148
+ if(cpuInfo2[1] & 0x40000) ret |= ISA_FEATURE_EVEX512;
149
+ return ret | ISA_LEVEL_VBMI2;
150
+ }
151
+ }
152
+
153
+ if((cpuInfo[1] & 0xC0010000) == 0xC0010000) { // AVX512BW + AVX512VL + AVX512F
154
+ ret |= ISA_FEATURE_EVEX512;
155
+ if(cpuInfo[2] & 0x40)
156
+ return ret | ISA_LEVEL_VBMI2;
157
+ return ret | ISA_LEVEL_AVX3;
150
158
  }
151
- }
152
-
153
- if(((xcr & 0xE0) == 0xE0) && (cpuInfo[1] & 0xC0010000) == 0xC0010000) { // AVX512BW + AVX512VL + AVX512F
154
- ret |= ISA_FEATURE_EVEX512;
155
- if(cpuInfo[2] & 0x40)
156
- return ret | ISA_LEVEL_VBMI2;
157
- return ret | ISA_LEVEL_AVX3;
158
159
  }
159
160
  // AVX2 is beneficial even on Zen1
160
161
  return ret | ISA_LEVEL_AVX2;
@@ -169,7 +170,7 @@ int cpu_supports_isa() {
169
170
  return ret | ISA_LEVEL_SSE2;
170
171
  }
171
172
 
172
- int cpu_supports_crc_isa() {
173
+ int RapidYenc::cpu_supports_crc_isa() {
173
174
  int flags[4];
174
175
  _cpuid1(flags);
175
176
 
@@ -200,7 +201,7 @@ int cpu_supports_crc_isa() {
200
201
  # endif
201
202
  # endif
202
203
  # endif
203
- bool cpu_supports_rvv() {
204
+ bool RapidYenc::cpu_supports_rvv() {
204
205
  # if defined(AT_HWCAP)
205
206
  unsigned long ret;
206
207
  # ifdef __FreeBSD__
package/src/yencode.cc CHANGED
@@ -11,6 +11,7 @@
11
11
  #include "crc.h"
12
12
 
13
13
  using namespace v8;
14
+ using namespace RapidYenc;
14
15
 
15
16
  static void free_buffer(char* data, void* _size) {
16
17
  #if !NODE_VERSION_AT_LEAST(0, 11, 0)
@@ -129,7 +130,7 @@ FUNC(Encode) {
129
130
  size_t dest_len = YENC_MAX_SIZE(arg_len, line_size);
130
131
 
131
132
  unsigned char *result = (unsigned char*) malloc(dest_len);
132
- size_t len = do_encode(line_size, &col, (const unsigned char*)node::Buffer::Data(args[0]), result, arg_len, true);
133
+ size_t len = encode(line_size, &col, (const unsigned char*)node::Buffer::Data(args[0]), result, arg_len, true);
133
134
  result = (unsigned char*)realloc(result, len);
134
135
  MARK_EXT_MEM(len);
135
136
  RETURN_VAL( NEW_BUFFER((char*)result, len, free_buffer, (void*)len) );
@@ -164,7 +165,7 @@ FUNC(EncodeTo) {
164
165
  if(node::Buffer::Length(args[1]) < dest_len)
165
166
  RETURN_ERROR("Destination buffer does not have enough space (use `maxSize` to compute required space)");
166
167
 
167
- size_t len = do_encode(line_size, &col, (const unsigned char*)node::Buffer::Data(args[0]), (unsigned char*)node::Buffer::Data(args[1]), arg_len, true);
168
+ size_t len = encode(line_size, &col, (const unsigned char*)node::Buffer::Data(args[0]), (unsigned char*)node::Buffer::Data(args[1]), arg_len, true);
168
169
  RETURN_VAL( Integer::New(ISOLATE len) );
169
170
  }
170
171
 
@@ -220,7 +221,7 @@ FUNC(EncodeIncr) {
220
221
  result = (unsigned char*) malloc(dest_len);
221
222
  }
222
223
 
223
- size_t len = do_encode(line_size, &col, (const unsigned char*)node::Buffer::Data(args[0]), result, arg_len, false);
224
+ size_t len = encode(line_size, &col, (const unsigned char*)node::Buffer::Data(args[0]), result, arg_len, false);
224
225
 
225
226
  SET_OBJ(ret, "written", Integer::New(ISOLATE len));
226
227
  if(allocResult) {
@@ -247,7 +248,7 @@ FUNC(Decode) {
247
248
  isRaw = ARG_TO_BOOL(args[1]);
248
249
 
249
250
  unsigned char *result = (unsigned char*) malloc(arg_len);
250
- size_t len = do_decode(isRaw, (const unsigned char*)node::Buffer::Data(args[0]), result, arg_len, NULL);
251
+ size_t len = decode(isRaw, (const unsigned char*)node::Buffer::Data(args[0]), result, arg_len, NULL);
251
252
  result = (unsigned char*)realloc(result, len);
252
253
  MARK_EXT_MEM(len);
253
254
  RETURN_VAL( NEW_BUFFER((char*)result, len, free_buffer, (void*)len) );
@@ -271,7 +272,7 @@ FUNC(DecodeTo) {
271
272
  if (args.Length() > 2)
272
273
  isRaw = ARG_TO_BOOL(args[2]);
273
274
 
274
- size_t len = do_decode(isRaw, (const unsigned char*)node::Buffer::Data(args[0]), (unsigned char*)node::Buffer::Data(args[1]), arg_len, NULL);
275
+ size_t len = decode(isRaw, (const unsigned char*)node::Buffer::Data(args[0]), (unsigned char*)node::Buffer::Data(args[1]), arg_len, NULL);
275
276
  RETURN_VAL( Integer::New(ISOLATE len) );
276
277
  }
277
278
 
@@ -310,7 +311,7 @@ FUNC(DecodeIncr) {
310
311
 
311
312
  if(allocResult) result = (unsigned char*) malloc(arg_len);
312
313
  unsigned char* dp = result;
313
- YencDecoderEnd ended = do_decode_end(&sp, &dp, arg_len, &state);
314
+ YencDecoderEnd ended = RapidYenc::decode_end((const void**)&sp, (void**)&dp, arg_len, &state);
314
315
  size_t len = dp - result;
315
316
  if(allocResult) result = (unsigned char*)realloc(result, len);
316
317
 
@@ -363,7 +364,7 @@ FUNC(CRC32) {
363
364
  RETURN_ERROR("Second argument must be a 4 byte buffer");
364
365
  crc = read_crc32(args[1]);
365
366
  }
366
- crc = do_crc32(
367
+ crc = crc32(
367
368
  (const void*)node::Buffer::Data(args[0]),
368
369
  node::Buffer::Length(args[0]),
369
370
  crc
@@ -447,7 +448,7 @@ FUNC(CRC32Shift) {
447
448
  static void init_all() {
448
449
  encoder_init();
449
450
  decoder_init();
450
- crc_init();
451
+ crc32_init();
451
452
  }
452
453
 
453
454
  #if NODE_VERSION_AT_LEAST(10, 7, 0)
@@ -81,12 +81,14 @@ module.exports = {
81
81
  module.exports._benchAsync(fn, cb, trials, []);
82
82
  }, asyncWait);
83
83
  },
84
- run: function(name, fn, sz2) {
84
+ run: function(name, fn, sz2, fn2) {
85
85
  var time = module.exports.bench(fn);
86
+ var time2 = fn2 ? module.exports.bench(fn2) : null;
86
87
  console.log(
87
88
  (name+' ').substring(0, 25) + ':'
88
89
  + fmtSpeed(sz*rounds, time)
89
- + (sz2 ? (' ' + fmtSpeed(sz2*rounds, time)) : '')
90
+ + ' ' + (sz2 ? fmtSpeed(sz2*rounds, time) : ' ')
91
+ + ' ' + (fn2 ? fmtSpeed(sz*rounds, time2) : ' ')
90
92
  );
91
93
  },
92
94
 
package/test/speeddec.js CHANGED
@@ -30,7 +30,7 @@ _.bufAvg2x.forEach(function(buf, i) {
30
30
 
31
31
  _.parseArgs('Syntax: node test/speeddec [-a|--average-only] [{-s|--sleep}=msecs(0)] [{-m|--methods}=clean,raw,rawincr]');
32
32
 
33
- console.log(' Test Output rate Read rate ');
33
+ console.log(' Test Output rate Read rate Output + CRC ');
34
34
 
35
35
  // warmup
36
36
  if(!_.sleep) {
@@ -43,51 +43,60 @@ if(!_.sleep) {
43
43
  });
44
44
  }
45
45
 
46
+ var decCrc = function(src, raw) {
47
+ var len = y.decodeTo(src, _.bufTarget, raw);
48
+ y.crc32(_.bufTarget.slice(0, len));
49
+ };
50
+ var decIncrCrc = function(src) {
51
+ var out = y.decodeIncr(src, 0, _.bufTarget);
52
+ y.crc32(_.bufTarget.slice(0, out.written));
53
+ };
54
+
46
55
  setTimeout(function() {
47
56
  if(!_.avgOnly) {
48
57
  if(_.decMethods.clean) {
49
- _.run('Clean worst (all escaping)', y.decodeTo.bind(null, mWorst, _.bufTarget), lenWorst);
50
- _.run('Clean best (min escaping)', y.decodeTo.bind(null, mBest, _.bufTarget), lenBest);
51
- _.run('Clean pass (no escaping)', y.decodeTo.bind(null, mBest2, _.bufTarget));
58
+ _.run('Clean worst (all escaping)', y.decodeTo.bind(null, mWorst, _.bufTarget), lenWorst, decCrc.bind(null, mWorst));
59
+ _.run('Clean best (min escaping)', y.decodeTo.bind(null, mBest, _.bufTarget), lenBest, decCrc.bind(null, mBest));
60
+ _.run('Clean pass (no escaping)', y.decodeTo.bind(null, mBest2, _.bufTarget), null, decCrc.bind(null, mBest2));
52
61
  }
53
62
  if(_.decMethods.raw) {
54
- _.run('Raw worst', y.decodeTo.bind(null, mWorst, _.bufTarget, true), lenWorst);
55
- _.run('Raw best', y.decodeTo.bind(null, mBest, _.bufTarget, true), lenBest);
56
- _.run('Raw pass', y.decodeTo.bind(null, mBest2, _.bufTarget, true));
63
+ _.run('Raw worst', y.decodeTo.bind(null, mWorst, _.bufTarget, true), lenWorst, decCrc.bind(null, mWorst, true));
64
+ _.run('Raw best', y.decodeTo.bind(null, mBest, _.bufTarget, true), lenBest, decCrc.bind(null, mBest, true));
65
+ _.run('Raw pass', y.decodeTo.bind(null, mBest2, _.bufTarget, true), null, decCrc.bind(null, mBest2, true));
57
66
  }
58
67
  if(_.decMethods.rawincr) {
59
- _.run('Raw-incr worst', y.decodeIncr.bind(null, mWorst, 0, _.bufTarget), lenWorst);
60
- _.run('Raw-incr best', y.decodeIncr.bind(null, mBest, 0, _.bufTarget), lenBest);
61
- _.run('Raw-incr pass', y.decodeIncr.bind(null, mBest2, 0, _.bufTarget));
68
+ _.run('Raw-incr worst', y.decodeIncr.bind(null, mWorst, 0, _.bufTarget), lenWorst, decIncrCrc.bind(null, mWorst));
69
+ _.run('Raw-incr best', y.decodeIncr.bind(null, mBest, 0, _.bufTarget), lenBest, decIncrCrc.bind(null, mBest));
70
+ _.run('Raw-incr pass', y.decodeIncr.bind(null, mBest2, 0, _.bufTarget), null, decIncrCrc.bind(null, mBest2));
62
71
  }
63
72
  }
64
73
 
65
74
  if(_.decMethods.clean)
66
75
  mAvg.forEach(function(buf, i) {
67
- _.run('Clean random ('+i+')', y.decodeTo.bind(null, buf, _.bufTarget), lenAvg[i]);
76
+ _.run('Clean random ('+i+')', y.decodeTo.bind(null, buf, _.bufTarget), lenAvg[i], decCrc.bind(null, buf));
68
77
  });
69
78
  if(_.decMethods.raw)
70
79
  mAvg.forEach(function(buf, i) {
71
- _.run('Raw random ('+i+')', y.decodeTo.bind(null, buf, _.bufTarget, true), lenAvg[i]);
80
+ _.run('Raw random ('+i+')', y.decodeTo.bind(null, buf, _.bufTarget, true), lenAvg[i], decCrc.bind(null, buf, true));
72
81
  });
73
82
  if(_.decMethods.rawincr) {
74
83
  mAvg.forEach(function(buf, i) {
75
- _.run('Raw-incr random ('+i+')', y.decodeIncr.bind(null, buf, 0, _.bufTarget), lenAvg[i]);
84
+ _.run('Raw-incr random ('+i+')', y.decodeIncr.bind(null, buf, 0, _.bufTarget), lenAvg[i], decIncrCrc.bind(null, buf));
76
85
  });
77
86
  }
78
87
 
79
88
  if(!_.avgOnly) {
80
89
  if(_.decMethods.clean)
81
90
  mAvg2x.forEach(function(buf, i) {
82
- _.run('Clean random 2xEsc ('+i+')', y.decodeTo.bind(null, buf, _.bufTarget), lenAvg2x[i]);
91
+ _.run('Clean random 2xEsc ('+i+')', y.decodeTo.bind(null, buf, _.bufTarget), lenAvg2x[i], decCrc.bind(null, buf));
83
92
  });
84
93
  if(_.decMethods.raw)
85
94
  mAvg2x.forEach(function(buf, i) {
86
- _.run('Raw random 2xEsc ('+i+')', y.decodeTo.bind(null, buf, _.bufTarget, true), lenAvg2x[i]);
95
+ _.run('Raw random 2xEsc ('+i+')', y.decodeTo.bind(null, buf, _.bufTarget, true), lenAvg2x[i], decCrc.bind(null, buf, true));
87
96
  });
88
97
  if(_.decMethods.rawincr)
89
98
  mAvg2x.forEach(function(buf, i) {
90
- _.run('Raw-incr random 2xEsc ('+i+')', y.decodeIncr.bind(null, buf, 0, _.bufTarget), lenAvg2x[i]);
99
+ _.run('Raw-incr random 2xEsc ('+i+')', y.decodeIncr.bind(null, buf, 0, _.bufTarget), lenAvg2x[i], decIncrCrc.bind(null, buf));
91
100
  });
92
101
  }
93
102
  }, _.sleep);
package/test/speedenc.js CHANGED
@@ -5,7 +5,7 @@ var _ = require('./_speedbase');
5
5
  _.parseArgs('Syntax: node test/speedenc [-a|--average-only] [{-s|--sleep}=msecs(0)]');
6
6
 
7
7
 
8
- console.log(' Test Read rate Output rate ');
8
+ console.log(' Test Read rate Output rate Read + CRC ');
9
9
 
10
10
  var lenWorst = y.encodeTo(_.bufWorst, _.bufTarget);
11
11
  var lenBest = y.encodeTo(_.bufBest, _.bufTarget);
@@ -13,31 +13,35 @@ var lenAvg = Array(_.bufAvg.length);
13
13
  var lenAvg2x = Array(_.bufAvg2x.length);
14
14
 
15
15
  // warmup
16
- if(!_.sleep) {
17
- _.bufAvg.forEach(function(buf, i) {
18
- var p=process.hrtime();
19
- for(var j=0;j<_.rounds;j+=1) lenAvg[i] = y.encodeTo(buf, _.bufTarget);
20
- var t=process.hrtime(p);
21
- });
22
- _.bufAvg2x.forEach(function(buf, i) {
23
- var p=process.hrtime();
24
- for(var j=0;j<_.rounds;j+=1) lenAvg2x[i] = y.encodeTo(buf, _.bufTarget);
25
- var t=process.hrtime(p);
26
- });
27
- }
16
+ var initRounds = _.sleep ? 1 : _.rounds;
17
+ _.bufAvg.forEach(function(buf, i) {
18
+ var p=process.hrtime();
19
+ for(var j=0;j<initRounds;j+=1) lenAvg[i] = y.encodeTo(buf, _.bufTarget);
20
+ var t=process.hrtime(p);
21
+ });
22
+ _.bufAvg2x.forEach(function(buf, i) {
23
+ var p=process.hrtime();
24
+ for(var j=0;j<initRounds;j+=1) lenAvg2x[i] = y.encodeTo(buf, _.bufTarget);
25
+ var t=process.hrtime(p);
26
+ });
27
+
28
+ var encCrc = function(src) {
29
+ y.encodeTo(src, _.bufTarget);
30
+ y.crc32(src);
31
+ };
28
32
 
29
33
  setTimeout(function() {
30
34
  if(!_.avgOnly) {
31
- _.run('Worst (all escaping)', y.encodeTo.bind(null, _.bufWorst, _.bufTarget), lenWorst);
32
- _.run('Best (no escaping)', y.encodeTo.bind(null, _.bufBest, _.bufTarget), lenBest);
35
+ _.run('Worst (all escaping)', y.encodeTo.bind(null, _.bufWorst, _.bufTarget), lenWorst, encCrc.bind(null, _.bufWorst));
36
+ _.run('Best (no escaping)', y.encodeTo.bind(null, _.bufBest, _.bufTarget), lenBest, encCrc.bind(null, _.bufBest));
33
37
  }
34
38
 
35
39
  _.bufAvg.forEach(function(buf, i) {
36
- _.run('Random ('+i+')', y.encodeTo.bind(null, buf, _.bufTarget), lenAvg[i]);
40
+ _.run('Random ('+i+')', y.encodeTo.bind(null, buf, _.bufTarget), lenAvg[i], encCrc.bind(null, buf));
37
41
  });
38
42
  if(!_.avgOnly) {
39
43
  _.bufAvg2x.forEach(function(buf, i) {
40
- _.run('Random 2xEsc ('+i+')', y.encodeTo.bind(null, buf, _.bufTarget), lenAvg2x[i]);
44
+ _.run('Random 2xEsc ('+i+')', y.encodeTo.bind(null, buf, _.bufTarget), lenAvg2x[i], encCrc.bind(null, buf));
41
45
  });
42
46
  }
43
47