Skip to content

Commit 699611c

Browse files
committed
Add unsigned FloatConvert lowering support on AArch64.
1 parent d257b7d commit 699611c

File tree

3 files changed

+56
-29
lines changed

3 files changed

+56
-29
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64ArithmeticLIRGenerator.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -286,24 +286,13 @@ protected Value emitMultiplyAddSub(AArch64ArithmeticOp op, Value a, Value b, Val
286286
}
287287

288288
protected static AArch64Kind getFloatConvertResultKind(FloatConvert op) {
289-
switch (op) {
290-
case F2I:
291-
case D2I:
292-
return AArch64Kind.DWORD;
293-
case F2L:
294-
case D2L:
295-
return AArch64Kind.QWORD;
296-
case I2F:
297-
case L2F:
298-
case D2F:
299-
return AArch64Kind.SINGLE;
300-
case I2D:
301-
case L2D:
302-
case F2D:
303-
return AArch64Kind.DOUBLE;
304-
default:
305-
throw GraalError.shouldNotReachHereUnexpectedValue(op); // ExcludeFromJacocoGeneratedReport
306-
}
289+
return switch (op) {
290+
case F2I, D2I, F2UI, D2UI -> AArch64Kind.DWORD;
291+
case F2L, D2L, F2UL, D2UL -> AArch64Kind.QWORD;
292+
case D2F, I2F, L2F, UI2F, UL2F -> AArch64Kind.SINGLE;
293+
case F2D, I2D, L2D, UI2D, UL2D -> AArch64Kind.DOUBLE;
294+
default -> throw GraalError.shouldNotReachHereUnexpectedValue(op); // ExcludeFromJacocoGeneratedReport
295+
};
307296
}
308297

309298
@Override

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64LoweringProviderMixin.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -88,4 +88,9 @@ default boolean supportsFoldingExtendIntoAccess(ExtendableMemoryAccess access, M
8888
}
8989
return false;
9090
}
91+
92+
@Override
93+
default boolean supportsUnsignedFloatConvert() {
94+
return true;
95+
}
9196
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/aarch64/AArch64Convert.java

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,9 +32,8 @@
3232
import jdk.graal.compiler.core.common.calc.FloatConvert;
3333
import jdk.graal.compiler.debug.Assertions;
3434
import jdk.graal.compiler.debug.GraalError;
35-
import jdk.graal.compiler.lir.asm.CompilationResultBuilder;
3635
import jdk.graal.compiler.lir.LIRInstructionClass;
37-
36+
import jdk.graal.compiler.lir.asm.CompilationResultBuilder;
3837
import jdk.vm.ci.code.Register;
3938
import jdk.vm.ci.meta.AllocatableValue;
4039

@@ -93,12 +92,24 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
9392
case D2L:
9493
masm.fcvtzs(toSize, fromSize, result, input);
9594
break;
95+
case F2UI:
96+
case D2UI:
97+
case F2UL:
98+
case D2UL:
99+
masm.fcvtzu(toSize, fromSize, result, input);
100+
break;
96101
case I2F:
97102
case I2D:
98103
case L2F:
99104
case L2D:
100105
masm.scvtf(toSize, fromSize, result, input);
101106
break;
107+
case UI2F:
108+
case UI2D:
109+
case UL2F:
110+
case UL2D:
111+
masm.ucvtf(toSize, fromSize, result, input);
112+
break;
102113
case D2F:
103114
case F2D:
104115
masm.fcvt(toSize, fromSize, result, input);
@@ -229,18 +240,24 @@ private boolean verifyConversionSizes(ElementSize dstESize, ElementSize srcESize
229240
switch (op) {
230241
case F2I:
231242
case I2F:
243+
case F2UI:
244+
case UI2F:
232245
assert srcESize == ElementSize.Word && dstESize == ElementSize.Word : Assertions.errorMessage(srcESize, dstESize);
233246
break;
234247
case F2D:
235248
case I2D:
249+
case UI2D:
236250
assert srcESize == ElementSize.Word && dstESize == ElementSize.DoubleWord : Assertions.errorMessage(srcESize, dstESize);
237251
break;
238252
case D2F:
239253
case D2I:
254+
case D2UI:
240255
assert srcESize == ElementSize.DoubleWord && dstESize == ElementSize.Word : Assertions.errorMessage(srcESize, dstESize);
241256
break;
242257
case D2L:
243258
case L2D:
259+
case D2UL:
260+
case UL2D:
244261
assert srcESize == ElementSize.DoubleWord && dstESize == ElementSize.DoubleWord : Assertions.errorMessage(srcESize, dstESize);
245262
break;
246263
}
@@ -258,17 +275,21 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
258275
Register input = asRegister(inputValue);
259276
switch (op) {
260277
case F2I:
261-
masm.neon.fcvtzsVV(size, srcESize, result, input);
262-
break;
263278
case D2L:
264279
masm.neon.fcvtzsVV(size, srcESize, result, input);
265280
break;
266-
case I2F:
267-
masm.neon.scvtfVV(size, srcESize, result, input);
281+
case F2UI:
282+
case D2UL:
283+
masm.neon.fcvtzuVV(size, srcESize, result, input);
268284
break;
285+
case I2F:
269286
case L2D:
270287
masm.neon.scvtfVV(size, srcESize, result, input);
271288
break;
289+
case UI2F:
290+
case UL2D:
291+
masm.neon.ucvtfVV(size, srcESize, result, input);
292+
break;
272293
case D2F:
273294
masm.neon.fcvtnVV(srcESize, result, input);
274295
break;
@@ -280,16 +301,28 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
280301
masm.neon.sxtlVV(srcESize, result, input);
281302
masm.neon.scvtfVV(size, ElementSize.fromKind(resultValue.getPlatformKind()), result, result);
282303
break;
304+
case UI2D:
305+
/* First unsigned extend int to long, then unsigned convert to double */
306+
masm.neon.uxtlVV(srcESize, result, input);
307+
masm.neon.ucvtfVV(size, ElementSize.fromKind(resultValue.getPlatformKind()), result, result);
308+
break;
283309
case D2I:
284-
/* First convert double to long, then to int */
310+
/* First convert double to long, then saturating extract int */
285311
masm.neon.fcvtzsVV(size, srcESize, result, input);
286-
masm.neon.xtnVV(dstESize, result, result);
312+
masm.neon.sqxtnVV(dstESize, result, result);
313+
break;
314+
case D2UI:
315+
/* First convert double to unsigned long, then saturating extract uint */
316+
masm.neon.fcvtzuVV(size, srcESize, result, input);
317+
masm.neon.uqxtnVV(dstESize, result, result);
287318
break;
288319
/*
289320
* It is not possible to handle these conversions correctly without losing fidelity.
290321
*/
291322
case F2L:
292323
case L2F:
324+
case F2UL:
325+
case UL2F:
293326
default:
294327
throw GraalError.shouldNotReachHere("Unsupported conversion requested."); // ExcludeFromJacocoGeneratedReport
295328
}

0 commit comments

Comments
 (0)