Last active
April 13, 2025 17:18
-
-
Save bitRAKE/412278b4de811193fb9ec1d6e77eec26 to your computer and use it in GitHub Desktop.
Bit vectors are a native type on x86 ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Create static bit vector: | |
; + ignore value set duplicates | |
; + invert value set when bit length is negative | |
struc(name) BITVECTOR bits,values& | |
local result,offset,char,inverted,_bits | |
virtual | |
offset = $ | |
db values ; string or byte array | |
result = 0 | |
while offset < $ | |
load char:1 from offset | |
offset = offset + 1 | |
result = result or (1 shl char) | |
end while | |
end virtual | |
if bits < 0 | |
_bits = -bits | |
inverted = (1 shl _bits) - 1 | |
else | |
_bits = bits | |
inverted = 0 | |
end if | |
if result shr _bits | |
err 'value exceeds bit vector size' | |
end if | |
name: emit (_bits + 7) shr 3 : (result xor inverted) | |
end struc | |
align 32 | |
InvalidFileNameChars BITVECTOR -256,"!#$%&'()-@^_`{}~+,.;=[]0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
FileNameValid__RSI: | |
xor eax,eax | |
.more: | |
lodsb | |
test eax,eax ; CF=0 | |
jz .done | |
bt [InvalidFileNameChars],eax | |
jnc .more | |
.done: | |
retn | |
; CF: file name has invalid characters | |
FileNameValid__RSI__ECX: ; ECX > 0 | |
.more: | |
dec ecx ; requres previous CF result on exit | |
js .done | |
movzx eax,byte[rsi+rcx] | |
bt [InvalidFileNameChars],eax | |
jnc .more | |
.done: | |
retn | |
; CF: file name has invalid characters | |
macro ValidateFileName reg0,reg1 | |
local more,done | |
more: dec reg32.#reg1 ; requres previous CF result on exit | |
js done | |
movzx eax,byte[reg0+reg1] | |
bt [InvalidFileNameChars],eax | |
jnc more | |
done: | |
end macro |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
align 32 | |
WSA0: BITVECTOR 20 shl 3,0x09,0x0A,0x0B,0x0C,0x0D,0x20 | |
WS2000: BITVECTOR 12 shl 3,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x28,0x29,0x2F,0x5F | |
; fast path the byte-like whitespace | |
UTF32_Whitespace: | |
cmp eax,0xA0 ; U+00A0 non-breaking space | |
jnc .high | |
bt [WSA0],eax ; [00-9F] ; 20 bytes | |
retn | |
.high: | |
jz .space | |
cmp eax,0x2000 | |
jc .notspace | |
cmp eax,0x2060 | |
jnc .cjk | |
bt [WS2000 - (0x2000 shr 3)],eax ; [2000-205F] ; 12 bytes | |
retn | |
.space: | |
stc | |
retn | |
.cjk: | |
; jz .space | |
cmp eax,0x3000 | |
jz .space | |
.notspace: | |
clc | |
retn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment