So i was really puzzled by the results i got earlier today and double checked everything. The function call and array locking overhead for the JNI function is really insignificant. To make sure that that -O2 doesn’t kill the array locking when i comment out the actual calculation code i also checked the generated assembler output. Here it is
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 |
_Java_com_badlogic_gdx_graphics_loaders_md5_MD5Jni_calculateVertices@28: pushl %ebp movl %esp, %ebp pushl %edi pushl %esi xorl %esi, %esi pushl %ebx subl $28, %esp movl 8(%ebp), %ebx movl 16(%ebp), %edx movl (%ebx), %eax movl %esi, 8(%esp) movl %edx, 4(%esp) movl %ebx, (%esp) call *888(%eax) movl 20(%ebp), %edx xorl %ecx, %ecx movl %eax, %edi movl (%ebx), %eax subl $12, %esp movl %ecx, 8(%esp) movl %edx, 4(%esp) movl %ebx, (%esp) call *888(%eax) xorl %edx, %edx subl $12, %esp movl %eax, %esi movl (%ebx), %eax movl %edx, 8(%esp) movl 24(%ebp), %edx movl %ebx, (%esp) movl %edx, 4(%esp) call *888(%eax) movl 28(%ebp), %edx xorl %ecx, %ecx subl $12, %esp movl %eax, -16(%ebp) movl (%ebx), %eax movl %ecx, 8(%esp) movl %edx, 4(%esp) movl %ebx, (%esp) call *888(%eax) xorl %edx, %edx subl $12, %esp movl %eax, -20(%ebp) movl (%ebx), %eax movl %edx, 12(%esp) movl 16(%ebp), %edx movl %edi, 8(%esp) xorl %edi, %edi movl %edx, 4(%esp) movl %ebx, (%esp) call *892(%eax) movl 20(%ebp), %edx movl (%ebx), %eax subl $16, %esp movl %edi, 12(%esp) movl %esi, 8(%esp) movl %edx, 4(%esp) movl %ebx, (%esp) call *892(%eax) movl -16(%ebp), %edx xorl %ecx, %ecx movl (%ebx), %eax subl $16, %esp movl %edx, 8(%esp) movl 24(%ebp), %edx movl %ecx, 12(%esp) movl %ebx, (%esp) movl %edx, 4(%esp) call *892(%eax) xorl %edx, %edx movl (%ebx), %eax subl $16, %esp movl %edx, 12(%esp) movl -20(%ebp), %edx movl %ebx, (%esp) movl %edx, 8(%esp) movl 28(%ebp), %edx movl %edx, 4(%esp) call *892(%eax) subl $16, %esp leal -12(%ebp), %esp popl %ebx popl %esi popl %edi popl %ebp ret $28 |
That’s GCC’s way of telling me two things: 1) I’m smarter than you 2) I inlined your function calls, lol :p. I didn’t just check the assembler output of the array locking only native method but also checked the assembler code for the fullblown version. To get myself comfortable with x86 assembler and AT&T syntax i first practiced to decode the assembler output of the unoptimized version. Here it is with some annotations. Compare to the C code of the last article:
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 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
_Java_com_badlogic_gdx_graphics_loaders_md5_MD5Jni_calculateVertices@28: pushl %ebp movl %esp, %ebp subl $152, %esp // float* pSkeleton = (float*)env->GetPrimitiveArrayCritical(skeleton, 0); movl $0, 8(%esp) movl 16(%ebp), %eax movl %eax, 4(%esp) movl 8(%ebp), %eax movl %eax, (%esp) call __ZN7JNIEnv_25GetPrimitiveArrayCriticalEP7_jarrayPh movl %eax, -4(%ebp) // float* pWeights = (float*)env->GetPrimitiveArrayCritical(weights, 0); movl $0, 8(%esp) movl 20(%ebp), %eax movl %eax, 4(%esp) movl 8(%ebp), %eax movl %eax, (%esp) call __ZN7JNIEnv_25GetPrimitiveArrayCriticalEP7_jarrayPh movl %eax, -8(%ebp) // float* pVerticesIn = (float*)env->GetPrimitiveArrayCritical(verticesIn, 0); movl $0, 8(%esp) movl 24(%ebp), %eax movl %eax, 4(%esp) movl 8(%ebp), %eax movl %eax, (%esp) call __ZN7JNIEnv_25GetPrimitiveArrayCriticalEP7_jarrayPh movl %eax, -12(%ebp) // float* pVerticesOut = (float*)env->GetPrimitiveArrayCritical(verticesOut, 0); movl $0, 8(%esp) movl 28(%ebp), %eax movl %eax, 4(%esp) movl 8(%ebp), %eax movl %eax, (%esp) call __ZN7JNIEnv_25GetPrimitiveArrayCriticalEP7_jarrayPh movl %eax, -16(%ebp) // int len = numVertices * 4; movl 32(%ebp), %eax sall $2, %eax // yay shift left movl %eax, -20(%ebp) // int vertexOffset = 2 movl $2, -24(%ebp) // k = 0; movl $0, -28(%ebp) // for( int vertexOffset = 2, k = 0; vertexOffset < len; vertexOffset += 4 ) // { L2: // vertexOffset < len movl -24(%ebp), %eax cmpl -20(%ebp), %eax jge L3 // float finalX = 0 movl $0x00000000, %eax movl %eax, -32(%ebp) // float finalY = 0 movl $0x00000000, %eax movl %eax, -36(%ebp) // float finalZ = 0 movl $0x00000000, %eax movl %eax, -40(%ebp) // load vertexOffset into eax // and pVerticesIn address into edx // then load the 32-bit float to the tos of the fpu stack movl -24(%ebp), %eax leal 0(,%eax,4), %edx movl -12(%ebp), %eax flds (%edx,%eax) // seems like its messing with the fpu status word, wtf? // stores it in ebp - 122, fiddles with it and then sets // the new status fnstcw -122(%ebp) movzwl -122(%ebp), %eax orw $3072, %ax movw %ax, -124(%ebp) fldcw -124(%ebp) // store (int)pVerticesIn[vertexOffset] in weightOffset fistpl -44(%ebp) // restore the old status word fldcw -122(%ebp) // loads vertex offset into eax and multiplies it by 4 (size of float) movl -24(%ebp), %eax sall $2, %eax // adds pVerticesIn for the address pVerticesIn[vertexOffset] addl -12(%ebp), %eax // adds 4 to the address to arrive at pVerticesIn[vertexOffset+1] addl $4, %eax // loads pVerticesIn[vertexOffset+1] to the fpu stack, fiddles with // the status word again and puts the integer into ebp-44, which is // weightCount flds (%eax) fldcw -124(%ebp) fistpl -48(%ebp) fldcw -122(%ebp) // weightOffset = (weightOffset << 2) + weightOffset; // load weight offset movl -44(%ebp), %eax // multiply weightOffset by 4, and old trick done via lea which can add and multiply leal 0(,%eax,4), %edx // add weightOffset one more time so we effectively multiply by 5, // this is even smarter than what i did in C/Java... leal -44(%ebp), %eax addl %edx, (%eax) // int j = 0 movl $0, -52(%ebp) // for( int j = 0; j < weightCount; j++ ) L5: // j < weightCount movl -52(%ebp), %eax cmpl -48(%ebp), %eax jge L6 // int jointOffset = (int)pWeights[weightOffset++] << 3; // Same shit as before, load pWeights[weightOffset] into // the fpu stack, convert to int and store in jointOffset (ebp-56) movl -44(%ebp), %eax leal 0(,%eax,4), %edx movl -8(%ebp), %eax flds (%edx,%eax) fldcw -124(%ebp) fistpl -128(%ebp) fldcw -122(%ebp) movl -128(%ebp), %eax sall $3, %eax movl %eax, -56(%ebp) // weightOffset++ leal -44(%ebp), %eax incl (%eax) // float bias = pWeights[weightOffset] // calculate the address of pWeights[weightOffset], base address plus offset movl -44(%ebp), %eax leal 0(,%eax,4), %ecx movl -8(%ebp), %edx // weightOffset++ leal -44(%ebp), %eax incl (%eax) // load content of pWeights[weightOffset] (funny that the increase of // weightOffset is done before hand...) and store it in bias (ebp-60) movl (%ecx,%edx), %eax movl %eax, -60(%ebp) // now we repeat that for vx, vy and vz... // float vx = pWeights[weightOffset++]; movl -44(%ebp), %eax leal 0(,%eax,4), %ecx movl -8(%ebp), %edx leal -44(%ebp), %eax incl (%eax) movl (%ecx,%edx), %eax movl %eax, -64(%ebp) // float vy = pWeights[weightOffset++]; movl -44(%ebp), %eax leal 0(,%eax,4), %ecx movl -8(%ebp), %edx leal -44(%ebp), %eax incl (%eax) movl (%ecx,%edx), %eax movl %eax, -68(%ebp) // float vz = pWeights[weightOffset++]; movl -44(%ebp), %eax leal 0(,%eax,4), %ecx movl -8(%ebp), %edx leal -44(%ebp), %eax incl (%eax) movl (%ecx,%edx), %eax movl %eax, -72(%ebp) // float qx = pSkeleton[jointOffset+4]; // first calcualte the address (multiply jointOffset by 4, add // the base address of pSkeleton and add another 4 floats which is // 16 bytes). fetch the float from pSkeleton[jointOffset+4] and // store it in qx (ebp-76) movl -56(%ebp), %eax sall $2, %eax addl -4(%ebp), %eax addl $16, %eax movl (%eax), %eax movl %eax, -76(%ebp) // float qy = pSkeleton[jointOffset+5]; // repeat the same thing for the other components of the // quaternion movl -56(%ebp), %eax sall $2, %eax addl -4(%ebp), %eax addl $20, %eax movl (%eax), %eax movl %eax, -80(%ebp) // float qz = pSkeleton[jointOffset+6]; movl -56(%ebp), %eax sall $2, %eax addl -4(%ebp), %eax addl $24, %eax movl (%eax), %eax movl %eax, -84(%ebp) // float qw = pSkeleton[jointOffset+7]; movl -56(%ebp), %eax sall $2, %eax addl -4(%ebp), %eax addl $28, %eax movl (%eax), %eax movl %eax, -88(%ebp) // float ix = -qx // woah, nice bit fiddling trick to negate a float! // repeated for all other inverted components of the quaternion movl -76(%ebp), %eax xorl $-2147483648, %eax movl %eax, -92(%ebp) // iy = -qy movl -80(%ebp), %eax xorl $-2147483648, %eax movl %eax, -96(%ebp) // iz = -qz movl -84(%ebp), %eax xorl $-2147483648, %eax movl %eax, -100(%ebp) // iw = qw movl -88(%ebp), %eax movl %eax, -104(%ebp) // float tw = -qx * vx - qy * vy - qz * vz; // first we load qx onto the fpu stack, why we // need to go over (ebp-132) is a riddle to me movl -76(%ebp), %eax movl %eax, -132(%ebp) flds -132(%ebp) // next we negate qx fchs // then we multiply it with vx (ebp-64) fmuls -64(%ebp) // we push -qx * vx and load qy onto the stack flds -80(%ebp) // we multiply qy with vy fmuls -68(%ebp) // and then substract qy * vy from -qx * vx which is // one slot below the top of stack. -qx * vx - qy * vy is // now in the top of the fpu stack fsubrp %st, %st(1) // next we push -qx * vx - qy * vy and load qz flds -84(%ebp) // we multiply qz with vz fmuls -72(%ebp) // then subtract it from -qx * vx - qy * vy fsubrp %st, %st(1) // and store the final result in tw (ebp-108). fstps -108(%ebp) // float tx = qw * vx + qy * vz - qz * vy; // load qw and multiply by vx flds -88(%ebp) fmuls -64(%ebp) // load qy and multiply by vz flds -80(%ebp) fmuls -72(%ebp) // add qw * vx and qy * vz faddp %st, %st(1) // load qz and multiply by vy flds -84(%ebp) fmuls -68(%ebp) // subtract qz * vy from qw * vx + qy * vz fsubrp %st, %st(1) // store result in tx fstps -112(%ebp) // float ty = qw * vy + qz * vx - qx * vz; // same shit as above only different operands... flds -88(%ebp) fmuls -68(%ebp) flds -84(%ebp) fmuls -64(%ebp) faddp %st, %st(1) flds -76(%ebp) fmuls -72(%ebp) fsubrp %st, %st(1) fstps -116(%ebp) // float tz = qw * vz + qx * vy - qy * vx; flds -88(%ebp) fmuls -72(%ebp) flds -76(%ebp) fmuls -68(%ebp) faddp %st, %st(1) flds -80(%ebp) fmuls -64(%ebp) fsubrp %st, %st(1) fstps -120(%ebp) // vx = tx * iw + tw * ix + ty * iz - tz * iy; // nothing new, result is in vx (ebp-64) flds -112(%ebp) fmuls -104(%ebp) flds -108(%ebp) fmuls -92(%ebp) faddp %st, %st(1) flds -116(%ebp) fmuls -100(%ebp) faddp %st, %st(1) flds -120(%ebp) fmuls -96(%ebp) fsubrp %st, %st(1) fstps -64(%ebp) // vy = ty * iw + tw * iy + tz * ix - tx * iz; // nothing new, result in vy (ebp - 68) flds -116(%ebp) fmuls -104(%ebp) flds -108(%ebp) fmuls -96(%ebp) faddp %st, %st(1) flds -120(%ebp) fmuls -92(%ebp) faddp %st, %st(1) flds -112(%ebp) fmuls -100(%ebp) fsubrp %st, %st(1) fstps -68(%ebp) // vz = tz * iw + tw * iz + tx * iy - ty * ix; // nothing new, result in vz (ebp - 72) flds -120(%ebp) fmuls -104(%ebp) flds -108(%ebp) fmuls -100(%ebp) faddp %st, %st(1) flds -112(%ebp) fmuls -96(%ebp) faddp %st, %st(1) flds -116(%ebp) fmuls -92(%ebp) fsubrp %st, %st(1) fstps -72(%ebp) // finalX += (pSkeleton[jointOffset+1] + vx) * bias; // we fetch pSkeleton[jointOffset+1] and load it to the top of // the fpu stack movl -56(%ebp), %eax sall $2, %eax addl -4(%ebp), %eax addl $4, %eax flds (%eax) // next we add vx to pSkeleton[jointOffset+1] and multiply by // bias fadds -64(%ebp) fmuls -60(%ebp) // then we push (pSkeleton[jointOffset+1] + vx)*bias, and load finalX flds -32(%ebp) // we add finalX to (pSkeleton[jointOffset+1] + vx)*bias // and store it back to finalX faddp %st, %st(1) fstps -32(%ebp) // finalY += (pSkeleton[jointOffset+2] + vy) * bias; movl -56(%ebp), %eax sall $2, %eax addl -4(%ebp), %eax addl $8, %eax flds (%eax) fadds -68(%ebp) fmuls -60(%ebp) flds -36(%ebp) faddp %st, %st(1) fstps -36(%ebp) finalZ += (pSkeleton[jointOffset+3] + vz) * bias; movl -56(%ebp), %eax sall $2, %eax addl -4(%ebp), %eax addl $12, %eax flds (%eax) fadds -72(%ebp) fmuls -60(%ebp) flds -40(%ebp) faddp %st, %st(1) fstps -40(%ebp) // j++ leal -52(%ebp), %eax incl (%eax) // back to for( int j = 0; j < weightCount; ) jmp L5 L6: // pVerticesOut[k++] = finalX; // fetch k and multiply it by 4 to get the offset from pVerticesOut in bytes movl -28(%ebp), %eax leal 0(,%eax,4), %ecx // store finalX in pVerticesOut[k] movl -16(%ebp), %edx movl -32(%ebp), %eax movl %eax, (%ecx,%edx) // k++ leal -28(%ebp), %eax incl (%eax) // pVerticesOut[k++] = finalY; // same as above movl -28(%ebp), %eax leal 0(,%eax,4), %ecx movl -16(%ebp), %edx movl -36(%ebp), %eax movl %eax, (%ecx,%edx) leal -28(%ebp), %eax incl (%eax) // pVerticesOut[k++] = finalZ; // same as above movl -28(%ebp), %eax leal 0(,%eax,4), %ecx movl -16(%ebp), %edx movl -40(%ebp), %eax movl %eax, (%ecx,%edx) leal -28(%ebp), %eax incl (%eax) // k += 2 leal -28(%ebp), %eax addl $2, (%eax) // vertexOffset += 4 leal -24(%ebp), %eax addl $4, (%eax) // go back to for( int vertexOffset = 0; vertexOffset < len; ) jmp L2 L3: // // just unlock the java arrays and return movl $0, 12(%esp) movl -4(%ebp), %eax movl %eax, 8(%esp) movl 16(%ebp), %eax movl %eax, 4(%esp) movl 8(%ebp), %eax movl %eax, (%esp) call __ZN7JNIEnv_29ReleasePrimitiveArrayCriticalEP7_jarrayPvl movl $0, 12(%esp) movl -8(%ebp), %eax movl %eax, 8(%esp) movl 20(%ebp), %eax movl %eax, 4(%esp) movl 8(%ebp), %eax movl %eax, (%esp) call __ZN7JNIEnv_29ReleasePrimitiveArrayCriticalEP7_jarrayPvl movl $0, 12(%esp) movl -12(%ebp), %eax movl %eax, 8(%esp) movl 24(%ebp), %eax movl %eax, 4(%esp) movl 8(%ebp), %eax movl %eax, (%esp) call __ZN7JNIEnv_29ReleasePrimitiveArrayCriticalEP7_jarrayPvl movl $0, 12(%esp) movl -16(%ebp), %eax movl %eax, 8(%esp) movl 28(%ebp), %eax movl %eax, 4(%esp) movl 8(%ebp), %eax movl %eax, (%esp) call __ZN7JNIEnv_29ReleasePrimitiveArrayCriticalEP7_jarrayPvl leave ret $28 |
Here’s the stackframe layout
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 |
ebp + 32 ... numVertices ebp + 28 ... verticesOut ebp + 24 ... verticesIn ebp + 20 ... weights ebp + 16 ... skeleton ebp + 12 ... class ebp + 8 ... env ebp + 4 ... no fucking idea, return address? ebp ... no fucking idea ebp - 4 ... pSkeleton ebp - 8 ... pWeights ebp - 12 ... pVerticesIn ebp - 16 ... pVerticesOut ebp - 20 ... len ebp - 24 ... vertexOffset ebp - 28 ... k ebp - 32 ... finalX ebp - 36 ... finalY ebp - 40 ... finalZ ebp - 44 ... weightOffset ebp - 48 ... weightCount ebp - 52 ... j ebp - 56 ... jointOffset ebp - 60 ... bias ebp - 64 ... vx ebp - 68 ... vy ebp - 72 ... vz ebp - 76 ... qx ebp - 80 ... qy ebp - 84 ... qz ebp - 88 ... qw ebp - 92 ... ix ebp - 96 ... iy ebp - 100 ... iz ebp - 104 ... iw ebp - 108 ... tw ebp - 112 ... tx ebp - 116 ... ty ebp - 120 ... tz |
I usually visualize the stack bottom up as that’s also the way local variables and arguments get laid out by gcc (at least relative to the base pointer…) That took me like an hour to decode and i was pretty proud of myself that i still “have it”. What’s immediatly clear is that there’s a shitload of load/stores to and from the stack in the unoptimized version. One could alter the array indexing in the C code to get rid of some of them. Then i turned on -O2, feeling confident that i would see what’s wrong in the actually used version.
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 |
_Java_com_badlogic_gdx_graphics_loaders_md5_MD5Jni_calculateVertices@28: pushl %ebp movl %esp, %ebp pushl %edi pushl %esi xorl %esi, %esi pushl %ebx subl $28, %esp movl 8(%ebp), %ebx movl 16(%ebp), %edx movl (%ebx), %eax movl %esi, 8(%esp) movl %edx, 4(%esp) movl %ebx, (%esp) call *888(%eax) movl 20(%ebp), %edx xorl %ecx, %ecx movl %eax, %edi movl (%ebx), %eax subl $12, %esp movl %ecx, 8(%esp) movl %edx, 4(%esp) movl %ebx, (%esp) call *888(%eax) xorl %edx, %edx subl $12, %esp movl %eax, %esi movl (%ebx), %eax movl %edx, 8(%esp) movl 24(%ebp), %edx movl %ebx, (%esp) movl %edx, 4(%esp) call *888(%eax) movl 28(%ebp), %edx xorl %ecx, %ecx subl $12, %esp movl %eax, -16(%ebp) movl (%ebx), %eax movl %ecx, 8(%esp) movl %edx, 4(%esp) movl %ebx, (%esp) call *888(%eax) xorl %edx, %edx subl $12, %esp movl %eax, -20(%ebp) movl (%ebx), %eax movl %edx, 12(%esp) movl 16(%ebp), %edx movl %edi, 8(%esp) xorl %edi, %edi movl %edx, 4(%esp) movl %ebx, (%esp) call *892(%eax) movl 20(%ebp), %edx movl (%ebx), %eax subl $16, %esp movl %edi, 12(%esp) movl %esi, 8(%esp) movl %edx, 4(%esp) movl %ebx, (%esp) call *892(%eax) movl -16(%ebp), %edx xorl %ecx, %ecx movl (%ebx), %eax subl $16, %esp movl %edx, 8(%esp) movl 24(%ebp), %edx movl %ecx, 12(%esp) movl %ebx, (%esp) movl %edx, 4(%esp) call *892(%eax) xorl %edx, %edx movl (%ebx), %eax subl $16, %esp movl %edx, 12(%esp) movl -20(%ebp), %edx movl %ebx, (%esp) movl %edx, 8(%esp) movl 28(%ebp), %edx movl %edx, 4(%esp) call *892(%eax) subl $16, %esp leal -12(%ebp), %esp popl %ebx popl %esi popl %edi popl %ebp ret $28 |
Now, i do not pretend that i can decipher this. I can see the basic program structure reflected by keeping track of were what local variables and argument is stored is impossible for me.
So i spent an hour diving into x86 code just to discover that i didn’t discover anything 🙂
UPDATE: I think i figured it out. It seems like the Sun HotSpot VM JIT compiles to SSE code in some circumstances. My code seems to trigger this. Find out more at http://java.sun.com/j2se/1.4.2/1.4.2_whitepaper.html#7. Yes, they do that since 1.4.2! The gcc code does not use any SIMD so it is at a disadvantage. Awesome sauce! The C version now takes 9 seconds with SSE enabled on my netbook (10.000 calls, the netbook is slow). With the 1.6.0.21 32-bit Client JVM it takes 11 seconds in Java. Suns JVM is indeed nice. Gotta test out JRockit and the IBM VM at some time.