@@ -333,7 +333,7 @@ static inline unsigned char search_escape_basic_neon(search_state *search)
333
333
if (search -> matches_mask > 0 ) {
334
334
return neon_next_match (search );
335
335
} else {
336
- // neon_next_match will only advance search->ptr up to the last matching character.
336
+ // neon_next_match will only advance search->ptr up to the last matching character.
337
337
// Skip over any characters in the last chunk that occur after the last match.
338
338
search -> has_matches = false;
339
339
search -> ptr = search -> chunk_end ;
@@ -342,40 +342,40 @@ static inline unsigned char search_escape_basic_neon(search_state *search)
342
342
343
343
/*
344
344
* The code below implements an SIMD-based algorithm to determine if N bytes at a time
345
- * need to be escaped.
346
- *
345
+ * need to be escaped.
346
+ *
347
347
* Assume the ptr = "Te\sting!" (the double quotes are included in the string)
348
- *
348
+ *
349
349
* The explanation will be limited to the first 8 bytes of the string for simplicity. However
350
350
* the vector insructions may work on larger vectors.
351
- *
351
+ *
352
352
* First, we load three constants 'lower_bound', 'backslash' and 'dblquote" in vector registers.
353
- *
354
- * lower_bound: [20 20 20 20 20 20 20 20]
355
- * backslash: [5C 5C 5C 5C 5C 5C 5C 5C]
356
- * dblquote: [22 22 22 22 22 22 22 22]
357
- *
358
- * Next we load the first chunk of the ptr:
353
+ *
354
+ * lower_bound: [20 20 20 20 20 20 20 20]
355
+ * backslash: [5C 5C 5C 5C 5C 5C 5C 5C]
356
+ * dblquote: [22 22 22 22 22 22 22 22]
357
+ *
358
+ * Next we load the first chunk of the ptr:
359
359
* [22 54 65 5C 73 74 69 6E] (" T e \ s t i n)
360
- *
360
+ *
361
361
* First we check if any byte in chunk is less than 32 (0x20). This returns the following vector
362
362
* as no bytes are less than 32 (0x20):
363
363
* [0 0 0 0 0 0 0 0]
364
- *
364
+ *
365
365
* Next, we check if any byte in chunk is equal to a backslash:
366
366
* [0 0 0 FF 0 0 0 0]
367
- *
367
+ *
368
368
* Finally we check if any byte in chunk is equal to a double quote:
369
- * [FF 0 0 0 0 0 0 0]
370
- *
369
+ * [FF 0 0 0 0 0 0 0]
370
+ *
371
371
* Now we have three vectors where each byte indicates if the corresponding byte in chunk
372
372
* needs to be escaped. We combine these vectors with a series of logical OR instructions.
373
373
* This is the needs_escape vector and it is equal to:
374
- * [FF 0 0 FF 0 0 0 0]
375
- *
374
+ * [FF 0 0 FF 0 0 0 0]
375
+ *
376
376
* Next we compute the bitwise AND between each byte and 0x1 and compute the horizontal sum of
377
377
* the values in the vector. This computes how many bytes need to be escaped within this chunk.
378
- *
378
+ *
379
379
* Finally we compute a mask that indicates which bytes need to be escaped. If the mask is 0 then,
380
380
* no bytes need to be escaped and we can continue to the next chunk. If the mask is not 0 then we
381
381
* have at least one byte that needs to be escaped.
@@ -394,15 +394,15 @@ static inline unsigned char search_escape_basic_neon(search_state *search)
394
394
return neon_next_match (search );
395
395
}
396
396
397
- // There are fewer than 16 bytes left.
397
+ // There are fewer than 16 bytes left.
398
398
unsigned long remaining = (search -> end - search -> ptr );
399
399
if (remaining >= SIMD_MINIMUM_THRESHOLD ) {
400
400
char * s = copy_remaining_bytes (search , sizeof (uint8x16_t ), remaining );
401
401
402
402
uint64_t mask = neon_rules_update (s );
403
403
404
404
if (!mask ) {
405
- // Nothing to escape, ensure search_flush doesn't do anything by setting
405
+ // Nothing to escape, ensure search_flush doesn't do anything by setting
406
406
// search->cursor to search->ptr.
407
407
fbuffer_consumed (search -> buffer , remaining );
408
408
search -> ptr = search -> end ;
@@ -476,7 +476,7 @@ static inline TARGET_SSE2 FORCE_INLINE unsigned char search_escape_basic_sse2(se
476
476
if (search -> matches_mask > 0 ) {
477
477
return sse2_next_match (search );
478
478
} else {
479
- // sse2_next_match will only advance search->ptr up to the last matching character.
479
+ // sse2_next_match will only advance search->ptr up to the last matching character.
480
480
// Skip over any characters in the last chunk that occur after the last match.
481
481
search -> has_matches = false;
482
482
if (RB_UNLIKELY (search -> chunk_base + sizeof (__m128i ) >= search -> end )) {
@@ -501,15 +501,15 @@ static inline TARGET_SSE2 FORCE_INLINE unsigned char search_escape_basic_sse2(se
501
501
return sse2_next_match (search );
502
502
}
503
503
504
- // There are fewer than 16 bytes left.
504
+ // There are fewer than 16 bytes left.
505
505
unsigned long remaining = (search -> end - search -> ptr );
506
506
if (remaining >= SIMD_MINIMUM_THRESHOLD ) {
507
507
char * s = copy_remaining_bytes (search , sizeof (__m128i ), remaining );
508
508
509
509
int needs_escape_mask = sse2_update (s );
510
510
511
511
if (needs_escape_mask == 0 ) {
512
- // Nothing to escape, ensure search_flush doesn't do anything by setting
512
+ // Nothing to escape, ensure search_flush doesn't do anything by setting
513
513
// search->cursor to search->ptr.
514
514
fbuffer_consumed (search -> buffer , remaining );
515
515
search -> ptr = search -> end ;
0 commit comments