Hash :
f3b25786
Author :
Date :
2021-10-05T21:25:23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
Procedure.i XorTwoBlocks2(*buffer1, *buffer2, length)
; move all the required data to source reg, destination reg and counter reg
!mov esi, [p.p_buffer1] ; read 32-bit integer from p.p_buffer1 and move to esi
!mov edi, [p.p_buffer2] ; read 32-bit integer from p.p_buffer2 and move to edi
!mov ecx, [p.v_length] ; read 32-bit integer from p.v_length and move to ecx
!@@: ; anonymous label, can be reached by @b (back) or @f (forward)
!mov al, byte [edi + ecx - 1] ; read byte from destination
!xor byte [esi + ecx - 1], al ; xor source with destination (i.e. xor bytes from both blocks)
!dec ecx ; decrease counter
!jne @b ; jumb back to first anonymous label behind
ProcedureReturn 0
EndProcedure
!jne label1
!jmp @b
!EXTERN printf
!DEFAULT rel
; source: http://www.jose.it-berater.org/smfforum/index.php?topic=5091.0
Procedure PopCount64(x.q)
!mov rax, [p.v_x]
!mov rdx, rax
!shr rdx, 1
!and rdx, [popcount64_v55]
!sub rax, rdx
;x = (x & $3333333333333333) + ((x >> 2) & $3333333333333333)
!mov rdx, rax ;x
!and rax, [popcount64_v33]
!shr rdx, 2
!and rdx, [popcount64_v33]
!add rax, rdx
;x = (x + (x >> 4)) & $0f0f0f0f0f0f0f0f0f0f
!mov rdx, rax
!shr rdx, 4
!add rax, rdx
!and rax, [popcount64_v0f]
;x * $0101010101010101 >> 56
!imul rax, [popcount64_v01]
!shr rax, 56
ProcedureReturn
!popcount64_v01: dq 0x0101010101010101
!popcount64_v0f: dq 0x0f0f0f0f0f0f0f0f
!popcount64_v33: dq 0x3333333333333333
!popcount64_v55: dq 0x5555555555555555
EndProcedure
----------------------------------------------------
[
["keyword", "Procedure"],
["punctuation", "."],
"i ",
["function", "XorTwoBlocks2"],
["punctuation", "("],
["operator", "*buffer1"],
["punctuation", ","],
["operator", "*buffer2"],
["punctuation", ","],
" length",
["punctuation", ")"],
["comment", "; move all the required data to source reg, destination reg and counter reg"],
["asm", [
["operator", "!"],
["function", "mov"],
["register", "esi"],
["operator", ","],
["operator", "["],
"p",
["operator", "."],
"p_buffer1",
["operator", "]"]
]],
["comment", "; read 32-bit integer from p.p_buffer1 and move to esi"],
["asm", [
["operator", "!"],
["function", "mov"],
["register", "edi"],
["operator", ","],
["operator", "["],
"p",
["operator", "."],
"p_buffer2",
["operator", "]"]
]],
["comment", "; read 32-bit integer from p.p_buffer2 and move to edi"],
["asm", [
["operator", "!"],
["function", "mov"],
["register", "ecx"],
["operator", ","],
["operator", "["],
"p",
["operator", "."],
"v_length",
["operator", "]"]
]],
["comment", "; read 32-bit integer from p.v_length and move to ecx"],
["asm", [
["operator", "!"],
["label", "@@"],
["operator", ":"]
]],
["comment", "; anonymous label, can be reached by @b (back) or @f (forward)"],
["asm", [
["operator", "!"],
["function", "mov"],
["register", "al"],
["operator", ","],
" byte ",
["operator", "["],
["register", "edi"],
["operator", "+"],
["register", "ecx"],
["operator", "-"],
["number", "1"],
["operator", "]"]
]],
["comment", "; read byte from destination"],
["asm", [
["operator", "!"],
["function", "xor"],
" byte ",
["operator", "["],
["register", "esi"],
["operator", "+"],
["register", "ecx"],
["operator", "-"],
["number", "1"],
["operator", "]"],
["operator", ","],
["register", "al"]
]],
["comment", "; xor source with destination (i.e. xor bytes from both blocks)"],
["asm", [
["operator", "!"],
["function", "dec"],
["register", "ecx"]
]],
["comment", "; decrease counter"],
["asm", [
["operator", "!"],
["function", "jne"],
["label-reference-anonymous", "@b"]
]],
["comment", "; jumb back to first anonymous label behind"],
["keyword", "ProcedureReturn"],
["number", "0"],
["keyword", "EndProcedure"],
["asm", [
["operator", "!"],
["function", "jne"],
["label-reference-addressed", "label1"]
]],
["asm", [
["operator", "!"],
["function", "jmp"],
["label-reference-anonymous", "@b"]
]],
["asm", [
["operator", "!"],
["keyword", "EXTERN printf"]
]],
["asm", [
["operator", "!"],
["keyword", "DEFAULT rel"]
]],
["comment", "; source: http://www.jose.it-berater.org/smfforum/index.php?topic=5091.0"],
["keyword", "Procedure"],
["function", "PopCount64"],
["punctuation", "("],
"x",
["punctuation", "."],
"q",
["punctuation", ")"],
["asm", [
["operator", "!"],
["function", "mov"],
["register", "rax"],
["operator", ","],
["operator", "["],
"p",
["operator", "."],
"v_x",
["operator", "]"]
]],
["asm", [
["operator", "!"],
["function", "mov"],
["register", "rdx"],
["operator", ","],
["register", "rax"]
]],
["asm", [
["operator", "!"],
["function", "shr"],
["register", "rdx"],
["operator", ","],
["number", "1"]
]],
["asm", [
["operator", "!"],
["function", "and"],
["register", "rdx"],
["operator", ","],
["operator", "["],
"popcount64_v55",
["operator", "]"]
]],
["asm", [
["operator", "!"],
["function", "sub"],
["register", "rax"],
["operator", ","],
["register", "rdx"]
]],
["comment", ";x = (x & $3333333333333333) + ((x >> 2) & $3333333333333333)"],
["asm", [
["operator", "!"],
["function", "mov"],
["register", "rdx"],
["operator", ","],
["register", "rax"]
]],
["comment", ";x"],
["asm", [
["operator", "!"],
["function", "and"],
["register", "rax"],
["operator", ","],
["operator", "["],
"popcount64_v33",
["operator", "]"]
]],
["asm", [
["operator", "!"],
["function", "shr"],
["register", "rdx"],
["operator", ","],
["number", "2"]
]],
["asm", [
["operator", "!"],
["function", "and"],
["register", "rdx"],
["operator", ","],
["operator", "["],
"popcount64_v33",
["operator", "]"]
]],
["asm", [
["operator", "!"],
["function", "add"],
["register", "rax"],
["operator", ","],
["register", "rdx"]
]],
["comment", ";x = (x + (x >> 4)) & $0f0f0f0f0f0f0f0f0f0f"],
["asm", [
["operator", "!"],
["function", "mov"],
["register", "rdx"],
["operator", ","],
["register", "rax"]
]],
["asm", [
["operator", "!"],
["function", "shr"],
["register", "rdx"],
["operator", ","],
["number", "4"]
]],
["asm", [
["operator", "!"],
["function", "add"],
["register", "rax"],
["operator", ","],
["register", "rdx"]
]],
["asm", [
["operator", "!"],
["function", "and"],
["register", "rax"],
["operator", ","],
["operator", "["],
"popcount64_v0f",
["operator", "]"]
]],
["comment", ";x * $0101010101010101 >> 56"],
["asm", [
["operator", "!"],
["function", "imul"],
["register", "rax"],
["operator", ","],
["operator", "["],
"popcount64_v01",
["operator", "]"]
]],
["asm", [
["operator", "!"],
["function", "shr"],
["register", "rax"],
["operator", ","],
["number", "56"]
]],
["keyword", "ProcedureReturn"],
["asm", [
["operator", "!"],
["label", "popcount64_v01"],
["operator", ":"],
["function-inline", "dq"],
["number", "0x0101010101010101"]
]],
["asm", [
["operator", "!"],
["label", "popcount64_v0f"],
["operator", ":"],
["function-inline", "dq"],
["number", "0x0f0f0f0f0f0f0f0f"]
]],
["asm", [
["operator", "!"],
["label", "popcount64_v33"],
["operator", ":"],
["function-inline", "dq"],
["number", "0x3333333333333333"]
]],
["asm", [
["operator", "!"],
["label", "popcount64_v55"],
["operator", ":"],
["function-inline", "dq"],
["number", "0x5555555555555555"]
]],
["keyword", "EndProcedure"]
]