-2

According to the "Arm Architecture Reference Manual Armv8, for Armv8-A architecture profile", there is an instruction FMOV (scalar, immediate). It is stated that "This instruction copies a floating-point immediate constant into the SIMD & FP destination register".

Is it possible to write a simple Java program that executes this instruction in an AArch64 machine? Also, how can I verify that the written program executes a particular instruction? Thanks.

PS1: I'm using Eclipse OpenJ9 VM (https://www.eclipse.org/openj9).
PS2: As javap is based on bytecode, it's not what I'm looking for. I also tried below commands, but was unable to verify the instruction execution-

java -Xjit:limit={<function_name>} -Xjit:verbose,vlog=<vlogfile_name> <class_name>
java -Xjit:verbose,vlog=<vlogfile_name> <class_name>
Protik
  • 53
  • 1
  • 9
  • 1
    `javap -v` isn't going to do anything for you: that's the Java bytecode, which is not machine-specific at all. – Louis Wasserman Aug 13 '20 at 18:43
  • @LouisWasserman Thanks, any thoughts on how to write such program & verification? – Protik Aug 13 '20 at 18:49
  • 1
    You would have to use JNI to use raw instructions. Or you could modify the JVM a bit – JCWasmx86 Aug 13 '20 at 18:50
  • 4
    Why do you need this? What problem are you trying to solve? – apangin Aug 13 '20 at 18:52
  • @JCWasmx86 Thanks, but I'm looking for a way to proceed this from a Java program point of view, instead of modifying JVM source code or using JNI. – Protik Aug 13 '20 at 18:52
  • https://stackoverflow.com/q/1503479/869736 will print the optimized assembly (when the JVM decides to optimize it). It's entirely up to the JIT to decide how to compile your program to assembly instructions. – Louis Wasserman Aug 13 '20 at 18:53
  • 1
    @Protik You can't write something like inline-assembly in Java. You have to use JNI,JNA or Project Panama – JCWasmx86 Aug 13 '20 at 18:55
  • @JCWasmx86 Would that be your answer instead of a comment? – Protik Aug 13 '20 at 18:57
  • Yes, it may be wrong, as I don't know, what you want to do exactly. – JCWasmx86 Aug 13 '20 at 18:58
  • @JCWasmx86 I am just trying to write a simple program that will execute this instruction in my machine & searching for a way to verify that. This isn't part of any problem or anything else. – Protik Aug 13 '20 at 19:02
  • Wouldn't be assembly/C better, if you want to execute an instruction, instead of relying on the mercy of the JIT-Compiler? – JCWasmx86 Aug 13 '20 at 19:05
  • Possibly, but there has to be a way to do this, I believe, even if some JIT options need to be tuned while compiling the program . If not, then I'd like some solid proof. – Protik Aug 13 '20 at 19:12
  • 2
    It's remarkable how this unusual question is being asked by different people ([1](https://www.quora.com/How-can-I-implement-native-instruction-i-e-FMOV-for-AArch64-in-an-open-source-JVM-general-guideline), [2](https://www.quora.com/My-boss-asked-me-to-make-use-of-an-instruction-like-FMOV-for-a-JVM-type-project-how-can-I-do-it-at-how-much-time-given-I-know-almost-nothing-about-compilers)). So, this is your homework / test assignment, isn't it? If so, please take a look, [how to ask homework questions](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions) – apangin Aug 13 '20 at 21:37
  • 1
    Your assumption couldn't be more wrong, it's neither a homework, nor an assignment. – Protik Aug 13 '20 at 22:08
  • @Protik If it isn't homework (which is defined here such that it include self-directed assignments) or an assignment, then what is it? – NomadMaker Aug 14 '20 at 03:43
  • @NomadMaker A question which will cause the end of mankind on earth, if there's unnecessary/ irrelevant comments. Just kidding! This is just a self-thought question, with no relation with any homework/assignment whatsoever, with some background searching of similar things on Stack Overflow, Google & Arm reference manual. Hoping to get more insightful comments. Cheers. – Protik Aug 14 '20 at 11:23
  • 1
    Voting to close this as opinion-based, since this is a concept not supported by the language and the results depend on an unreasonable amount of environmental factors. – Siguza Aug 16 '20 at 08:16
  • If a question is unusual & the answer isn't known, I think it's not ideal to tag it as a homework, without actually knowing this. – Protik Aug 17 '20 at 12:27

2 Answers2

0

Reading the armv8 spec:

The Floating-point move (register) instructions copy a scalar floating-point value from one register to another register without performing any conversion. Some of the Floating-point move (register) instructions overlap with the functionality provided by the Advanced SIMD instructions DUP , INS , and UMOV . However, Arm recommends using the FMOV instructions when operating on scalar floating-point data to avoid the creation of scalar floating-point code that depends on the availability of the Advanced SIMD instruction set. Table C3-64 shows the Floating-point move (register) instructions.

The spec suggests that this instruction is the only way to move from a floating point register to a general purpose register, if the listed SIMD instructions aren't available. So you need java code that converts a float to an int without performing a conversion, and a processor that doesn't have SIMD support.

The defacto way to do this in java seems to be Float.floatToIntBits.

On my JVM install(hotspot jdk8u forest) this is implemented as a native function. This native function eventually reaches hotspot/src/share/vm/opto/library_call.cpp, with the following code:

case vmIntrinsics::_floatToRawIntBits:
  case vmIntrinsics::_floatToIntBits:
  case vmIntrinsics::_intBitsToFloat:
  case vmIntrinsics::_doubleToRawLongBits:
  case vmIntrinsics::_doubleToLongBits:
  case vmIntrinsics::_longBitsToDouble:         
return inline_fp_conversions(intrinsic_id());

The definition of inline_fp_conversions is in the same file and as far as I can tell could output a FMOV instruction.

Notably MoveF2INode is emited, though this may end up calling native code instead of actually JIT'ing an FMOV.

I'm a little conflicted, since it appears this question could be a homework question. But if this is the answer homework-issuer is looking for it seems like a dumb homework question, so I'm fine with this answer existing.

PiRocks
  • 1,708
  • 2
  • 18
  • 29
  • thanks for your answer. Now I am clearer. But I still don't understand how I can be sure that this instruction (or any other instead of this) is executed for the Java code as the mentioned link (in the comments) talks about Sun Hotspot JVM which is different for my case. I have clarified in the comments about this question being a homework or not. I can't imagine there'd be a homework question like this, I maybe wrong. – Protik Aug 17 '20 at 12:00
  • 1
    You can't be sure that FMOV will be executed(without debugging/logging to find out what is actually executed). One would have to read openj9's source code to determine exactly what happens different to hotspot. – PiRocks Aug 17 '20 at 20:41
0

Although it is not possible to be certain if this instruction will be executed before the program runs, we can find-out the executed instructions by HotSpot Disassembler (hsdis) and the opcodes associated with the instructions of a simple Java program. For getting the respective opcodes, first, a log file needs to be generated. Then, by using this log file, a trace file needs to be generated to find-out what the executed opcodes are for 'that' particular program. In this case, it is better to limit the generation of the trace file for the targeted function only. Because that would be a big file otherwise.

A simple Java program with this statement- x = x*2.0F; running on a loop of 10 million times caused the execution of this instruction.

Protik
  • 53
  • 1
  • 9