mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-08 17:38:38 +00:00
8297539: Use PrimitiveConversions::cast for local uses of the int<->float union conversion trick
Reviewed-by: coleenp, kbarrett, dholmes
This commit is contained in:
parent
8eb4e7e07e
commit
a19b28ab3e
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2020 Red Hat Inc. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
@ -29,6 +29,7 @@
|
||||
#include "compiler/disassembler.hpp"
|
||||
#include "immediate_aarch64.hpp"
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "metaprogramming/primitiveConversions.hpp"
|
||||
|
||||
#ifndef PRODUCT
|
||||
const uintptr_t Assembler::asm_bp = 0x0000ffffac221240;
|
||||
@ -499,12 +500,8 @@ unsigned Assembler::pack(double value) {
|
||||
// Packed operands for Floating-point Move (immediate)
|
||||
|
||||
static float unpack(unsigned value) {
|
||||
union {
|
||||
unsigned ival;
|
||||
float val;
|
||||
};
|
||||
ival = fp_immediate_for_encoding(value, 0);
|
||||
return val;
|
||||
unsigned ival = fp_immediate_for_encoding(value, 0);
|
||||
return PrimitiveConversions::cast<float>(ival);
|
||||
}
|
||||
|
||||
address Assembler::locate_next_instruction(address inst) {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
@ -26,8 +27,9 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
#include "immediate_aarch64.hpp"
|
||||
#include "metaprogramming/primitiveConversions.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
|
||||
// there are at most 2^13 possible logical immediate encodings
|
||||
// however, some combinations of immr and imms are invalid
|
||||
@ -431,11 +433,7 @@ uint32_t encoding_for_fp_immediate(float immediate)
|
||||
// return the imm8 result [s:r:f]
|
||||
//
|
||||
|
||||
union {
|
||||
float fpval;
|
||||
uint32_t val;
|
||||
};
|
||||
fpval = immediate;
|
||||
uint32_t val = PrimitiveConversions::cast<uint32_t>(immediate);
|
||||
uint32_t s, r, f, res;
|
||||
// sign bit is 31
|
||||
s = (val >> 31) & 0x1;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -279,37 +279,31 @@ class VFP {
|
||||
class float_num : public fpnum {
|
||||
public:
|
||||
float_num(float v) {
|
||||
_num.val = v;
|
||||
_bits = PrimitiveConversions::cast<unsigned int>(v);
|
||||
}
|
||||
|
||||
virtual unsigned int f_hi4() const { return (_num.bits << 9) >> (19+9); }
|
||||
virtual bool f_lo_is_null() const { return (_num.bits & ((1 << 19) - 1)) == 0; }
|
||||
virtual int e() const { return ((_num.bits << 1) >> (23+1)) - 127; }
|
||||
virtual unsigned int s() const { return _num.bits >> 31; }
|
||||
unsigned int f_hi4() const override { return (_bits << 9) >> (19+9); }
|
||||
bool f_lo_is_null() const override { return (_bits & ((1 << 19) - 1)) == 0; }
|
||||
int e() const override { return ((_bits << 1) >> (23+1)) - 127; }
|
||||
unsigned int s() const override { return _bits >> 31; }
|
||||
|
||||
private:
|
||||
union {
|
||||
float val;
|
||||
unsigned int bits;
|
||||
} _num;
|
||||
unsigned int _bits;
|
||||
};
|
||||
|
||||
class double_num : public fpnum {
|
||||
public:
|
||||
double_num(double v) {
|
||||
_num.val = v;
|
||||
_bits = PrimitiveConversions::cast<uint64_t>(v);
|
||||
}
|
||||
|
||||
virtual unsigned int f_hi4() const { return (_num.bits << 12) >> (48+12); }
|
||||
virtual bool f_lo_is_null() const { return (_num.bits & ((1LL << 48) - 1)) == 0; }
|
||||
virtual int e() const { return ((_num.bits << 1) >> (52+1)) - 1023; }
|
||||
virtual unsigned int s() const { return _num.bits >> 63; }
|
||||
unsigned int f_hi4() const override { return (_bits << 12) >> (48+12); }
|
||||
bool f_lo_is_null() const override { return (_bits & ((1LL << 48) - 1)) == 0; }
|
||||
int e() const override { return ((_bits << 1) >> (52+1)) - 1023; }
|
||||
unsigned int s() const override { return _bits >> 63; }
|
||||
|
||||
private:
|
||||
union {
|
||||
double val;
|
||||
unsigned long long bits;
|
||||
} _num;
|
||||
uint64_t _bits;
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -37,6 +37,7 @@
|
||||
#include "interpreter/bytecodeHistogram.hpp"
|
||||
#include "interpreter/interpreter.hpp"
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "metaprogramming/primitiveConversions.hpp"
|
||||
#include "oops/accessDecorators.hpp"
|
||||
#include "oops/klass.inline.hpp"
|
||||
#include "prims/methodHandles.hpp"
|
||||
@ -673,15 +674,11 @@ void MacroAssembler::mov_metadata(Register rd, Metadata* o, int metadata_index)
|
||||
|
||||
void MacroAssembler::mov_float(FloatRegister fd, jfloat c, AsmCondition cond) {
|
||||
Label skip_constant;
|
||||
union {
|
||||
jfloat f;
|
||||
jint i;
|
||||
} accessor;
|
||||
accessor.f = c;
|
||||
jint float_bits = PrimitiveConversions::cast<jint>(c);
|
||||
|
||||
flds(fd, Address(PC), cond);
|
||||
b(skip_constant);
|
||||
emit_int32(accessor.i);
|
||||
emit_int32(float_bits);
|
||||
bind(skip_constant);
|
||||
}
|
||||
|
||||
|
||||
@ -46,6 +46,7 @@
|
||||
#include "logging/log.hpp"
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "memory/universe.hpp"
|
||||
#include "metaprogramming/primitiveConversions.hpp"
|
||||
#include "oops/compiledICHolder.inline.hpp"
|
||||
#include "oops/klass.hpp"
|
||||
#include "oops/method.inline.hpp"
|
||||
@ -242,12 +243,11 @@ JRT_LEAF(jfloat, SharedRuntime::frem(jfloat x, jfloat y))
|
||||
#ifdef _WIN64
|
||||
// 64-bit Windows on amd64 returns the wrong values for
|
||||
// infinity operands.
|
||||
union { jfloat f; juint i; } xbits, ybits;
|
||||
xbits.f = x;
|
||||
ybits.f = y;
|
||||
juint xbits = PrimitiveConversions::cast<juint>(x);
|
||||
juint ybits = PrimitiveConversions::cast<juint>(y);
|
||||
// x Mod Infinity == x unless x is infinity
|
||||
if (((xbits.i & float_sign_mask) != float_infinity) &&
|
||||
((ybits.i & float_sign_mask) == float_infinity) ) {
|
||||
if (((xbits & float_sign_mask) != float_infinity) &&
|
||||
((ybits & float_sign_mask) == float_infinity) ) {
|
||||
return x;
|
||||
}
|
||||
return ((jfloat)fmod_winx64((double)x, (double)y));
|
||||
@ -258,12 +258,11 @@ JRT_END
|
||||
|
||||
JRT_LEAF(jdouble, SharedRuntime::drem(jdouble x, jdouble y))
|
||||
#ifdef _WIN64
|
||||
union { jdouble d; julong l; } xbits, ybits;
|
||||
xbits.d = x;
|
||||
ybits.d = y;
|
||||
julong xbits = PrimitiveConversions::cast<julong>(x);
|
||||
julong ybits = PrimitiveConversions::cast<julong>(y);
|
||||
// x Mod Infinity == x unless x is infinity
|
||||
if (((xbits.l & double_sign_mask) != double_infinity) &&
|
||||
((ybits.l & double_sign_mask) == double_infinity) ) {
|
||||
if (((xbits & double_sign_mask) != double_infinity) &&
|
||||
((ybits & double_sign_mask) == double_infinity) ) {
|
||||
return x;
|
||||
}
|
||||
return ((jdouble)fmod_winx64((double)x, (double)y));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user