Skip to content

Instantly share code, notes, and snippets.

@quinnj
Created February 25, 2018 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quinnj/df388d2946503593c2124f9de1039a95 to your computer and use it in GitHub Desktop.
Save quinnj/df388d2946503593c2124f9de1039a95 to your computer and use it in GitHub Desktop.
const BYTES = fill(false, 128)
BYTES[Int(',')] = true
BYTES[Int('\n')] = true
BYTES[Int('\r')] = true
const COMMA = UInt8(',')
const NEWLINE = UInt8('\n')
const RETURN = UInt8('\r')
function parse(file="/home/chronos/user/Downloads/.julia/v0.7/CSV/test/test_files/Fielding.csv")
m = Mmap.mmap(file)
bitmap = zeros(UInt8, fld1(length(m), 8))
return parse(m, bitmap)
end
#TODO
# try perf on not unrolling inner loop
# check if actually simd
#•
function parse(m::Vector{UInt8}, bitmap::Vector{UInt8})
i = 1
j = 1
len = length(m)
@simd for i = 1:8:len
@inbounds begin
b = m[i]
mask = ifelse(BYTES[b], 0b00000001, 0b00000000)
b = m[i+1]
mask |= ifelse(BYTES[b], 0b00000010, 0b00000000)
b = m[i+2]
mask |= ifelse(BYTES[b], 0b00000100, 0b00000000)
b = m[i+3]
mask |= ifelse(BYTES[b], 0b00001000, 0b00000000)
b = m[i+4]
mask |= ifelse(BYTES[b], 0b00010000, 0b00000000)
b = m[i+5]
mask |= ifelse(BYTES[b], 0b00100000, 0b00000000)
b = m[i+6]
mask |= ifelse(BYTES[b], 0b01000000, 0b00000000)
b = m[i+7]
mask |= ifelse(BYTES[b], 0b10000000, 0b00000000)
bitmap[j] = mask
end
j += 1
end
return bitmap
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment