Skip to content

Instantly share code, notes, and snippets.

@Pikachuxxxx
Created October 30, 2025 05:24
Show Gist options
  • Save Pikachuxxxx/fc112acac649f16045d9063d28d9d3f1 to your computer and use it in GitHub Desktop.
Save Pikachuxxxx/fc112acac649f16045d9063d28d9d3f1 to your computer and use it in GitHub Desktop.
how to solve some problems, just my thoughts
1. How to convert a string to integer with SIMD acceleration (explained with NEON intrinsics)
// vld1q_u8 to load 16 chars
// create masks:
// is_digit (0-9) using vceq_u8
// is_plus --> vaddvq_u8 --> to get quick answer --> update global state
// is_minus --> vaddvq_u8 --> to get quick answer --> update global state
// is_space
// ignore_mask = vorrq_u8 --> combine masks (is_plus/minus/space)
// convert to digits --> subtrack '0', vsubq_u8/vdupq_u8
// apply digit mask and convert them to 0, vbslq_u8
// apply ignore_mask and zero out unwanted digit conversions
// read until we get first non-zero and accumulate until next 0 and break --> chance to early exit!
// unroll reading 16 bytes and checking and early exit
// append to string if != 0, if first 0 toggle a global flag to exit at next 0
// loop until we run out of chars or get \0 and process the tail char by char
================================================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment