title: Code injecting/assembly inlining in Java?
body: <p>I know Java is a secure language but when matrix calculations are needed, can I try something faster?</p>
  
  <p>I am learning __asm{} in C++, Digital-Mars compiler and FASM. I want to do the same in Java. How can I inline assembly codes in functions? Is this even possible?</p>
  
  <p>Something like this (a vectorized loop to clamp all elements of an array to a value without branching, using AVX support of CPU):</p>
  
  <pre><code>JavaAsmBlock(
     # get pointers into registers somehow
     # and tell Java which registers the asm clobbers somehow
       vbroadcastss  twenty_five(%rip), %ymm0
       xor   %edx,%edx
  .Lloop:                            # do {
      vmovups   (%rsi, %rdx, 4), %ymm1
      vcmpltps   %ymm1, %ymm0, %ymm2
      vblendvps  %ymm2, %ymm0, %ymm1, %ymm1  # TODO: use vminps instead
      vmovups    %ymm1, (%rdi, %rdx, 4)
      # TODO: unroll the loop a bit, and maybe handle unaligned output specially if that's common
      add         $32, %rdx
      cmp         %rcx, %rdx
      jb     .Lloop                  # } while(idx &lt; count)
      vzeroupper
  );
  
  System.out.println(var[0]);
  </code></pre>
  
  <p>I don't want to use a code-injector. I want to see the Intel or AT&amp;T style x86 instructions.</p>