Skip to content
Permalink
Browse files
8248403: AArch64: Remove uses of kernel integer types
Reviewed-by: stuefe
Backport-of: 6a91c73
  • Loading branch information
Paul Hohensee committed Aug 16, 2021
1 parent 3db0637 commit 5ce46d9679fd9c9010bcfe55fd723a0f068b3333
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 103 deletions.
@@ -2968,7 +2968,7 @@ encode %{

enc_class aarch64_enc_movw_imm(iRegI dst, immI src) %{
MacroAssembler _masm(&cbuf);
u_int32_t con = (u_int32_t)$src$$constant;
uint32_t con = (uint32_t)$src$$constant;
Register dst_reg = as_Register($dst$$reg);
if (con == 0) {
__ movw(dst_reg, zr);
@@ -2980,7 +2980,7 @@ encode %{
enc_class aarch64_enc_mov_imm(iRegL dst, immL src) %{
MacroAssembler _masm(&cbuf);
Register dst_reg = as_Register($dst$$reg);
u_int64_t con = (u_int64_t)$src$$constant;
uint64_t con = (uint64_t)$src$$constant;
if (con == 0) {
__ mov(dst_reg, zr);
} else {
@@ -3022,7 +3022,7 @@ encode %{
enc_class aarch64_enc_mov_p1(iRegP dst, immP_1 src) %{
MacroAssembler _masm(&cbuf);
Register dst_reg = as_Register($dst$$reg);
__ mov(dst_reg, (u_int64_t)1);
__ mov(dst_reg, (uint64_t)1);
%}

enc_class aarch64_enc_mov_poll_page(iRegP dst, immPollPage src) %{
@@ -3156,7 +3156,7 @@ encode %{
enc_class aarch64_enc_cmpw_imm(iRegI src1, immI src2) %{
MacroAssembler _masm(&cbuf);
Register reg1 = as_Register($src1$$reg);
u_int32_t val = (u_int32_t)$src2$$constant;
uint32_t val = (uint32_t)$src2$$constant;
__ movw(rscratch1, val);
__ cmpw(reg1, rscratch1);
%}
@@ -3178,15 +3178,15 @@ encode %{
__ adds(zr, reg, -val);
} else {
// aargh, Long.MIN_VALUE is a special case
__ orr(rscratch1, zr, (u_int64_t)val);
__ orr(rscratch1, zr, (uint64_t)val);
__ subs(zr, reg, rscratch1);
}
%}

enc_class aarch64_enc_cmp_imm(iRegL src1, immL src2) %{
MacroAssembler _masm(&cbuf);
Register reg1 = as_Register($src1$$reg);
u_int64_t val = (u_int64_t)$src2$$constant;
uint64_t val = (uint64_t)$src2$$constant;
__ mov(rscratch1, val);
__ cmp(reg1, rscratch1);
%}
@@ -13444,16 +13444,16 @@ instruct clearArray_reg_reg(iRegL_R11 cnt, iRegP_R10 base, Universe dummy, rFlag

instruct clearArray_imm_reg(immL cnt, iRegP_R10 base, Universe dummy, rFlagsReg cr)
%{
predicate((u_int64_t)n->in(2)->get_long()
< (u_int64_t)(BlockZeroingLowLimit >> LogBytesPerWord));
predicate((uint64_t)n->in(2)->get_long()
< (uint64_t)(BlockZeroingLowLimit >> LogBytesPerWord));
match(Set dummy (ClearArray cnt base));
effect(USE_KILL base);

ins_cost(4 * INSN_COST);
format %{ "ClearArray $cnt, $base" %}

ins_encode %{
__ zero_words($base$$Register, (u_int64_t)$cnt$$constant);
__ zero_words($base$$Register, (uint64_t)$cnt$$constant);
%}

ins_pipe(pipe_class_memory);
@@ -2042,7 +2042,7 @@ void LIR_Assembler::comp_fl2i(LIR_Code code, LIR_Opr left, LIR_Opr right, LIR_Op
} else if (code == lir_cmp_l2i) {
Label done;
__ cmp(left->as_register_lo(), right->as_register_lo());
__ mov(dst->as_register(), (u_int64_t)-1L);
__ mov(dst->as_register(), (uint64_t)-1L);
__ br(Assembler::LT, done);
__ csinc(dst->as_register(), zr, zr, Assembler::EQ);
__ bind(done);
@@ -23,6 +23,7 @@
*/

#include <stdlib.h>
#include <stdint.h>
#include "immediate_aarch64.hpp"

// there are at most 2^13 possible logical immediate encodings
@@ -34,14 +35,14 @@ static int li_table_entry_count;
// for forward lookup we just use a direct array lookup
// and assume that the cient has supplied a valid encoding
// table[encoding] = immediate
static u_int64_t LITable[LI_TABLE_SIZE];
static uint64_t LITable[LI_TABLE_SIZE];

// for reverse lookup we need a sparse map so we store a table of
// immediate and encoding pairs sorted by immediate value

struct li_pair {
u_int64_t immediate;
u_int32_t encoding;
uint64_t immediate;
uint32_t encoding;
};

static struct li_pair InverseLITable[LI_TABLE_SIZE];
@@ -63,71 +64,71 @@ int compare_immediate_pair(const void *i1, const void *i2)
// helper functions used by expandLogicalImmediate

// for i = 1, ... N result<i-1> = 1 other bits are zero
static inline u_int64_t ones(int N)
static inline uint64_t ones(int N)
{
return (N == 64 ? (u_int64_t)-1UL : ((1UL << N) - 1));
return (N == 64 ? (uint64_t)-1UL : ((1UL << N) - 1));
}

/*
* bit twiddling helpers for instruction decode
*/

// 32 bit mask with bits [hi,...,lo] set
static inline u_int32_t mask32(int hi = 31, int lo = 0)
static inline uint32_t mask32(int hi = 31, int lo = 0)
{
int nbits = (hi + 1) - lo;
return ((1 << nbits) - 1) << lo;
}

static inline u_int64_t mask64(int hi = 63, int lo = 0)
static inline uint64_t mask64(int hi = 63, int lo = 0)
{
int nbits = (hi + 1) - lo;
return ((1L << nbits) - 1) << lo;
}

// pick bits [hi,...,lo] from val
static inline u_int32_t pick32(u_int32_t val, int hi = 31, int lo = 0)
static inline uint32_t pick32(uint32_t val, int hi = 31, int lo = 0)
{
return (val & mask32(hi, lo));
}

// pick bits [hi,...,lo] from val
static inline u_int64_t pick64(u_int64_t val, int hi = 31, int lo = 0)
static inline uint64_t pick64(uint64_t val, int hi = 31, int lo = 0)
{
return (val & mask64(hi, lo));
}

// mask [hi,lo] and shift down to start at bit 0
static inline u_int32_t pickbits32(u_int32_t val, int hi = 31, int lo = 0)
static inline uint32_t pickbits32(uint32_t val, int hi = 31, int lo = 0)
{
return (pick32(val, hi, lo) >> lo);
}

// mask [hi,lo] and shift down to start at bit 0
static inline u_int64_t pickbits64(u_int64_t val, int hi = 63, int lo = 0)
static inline uint64_t pickbits64(uint64_t val, int hi = 63, int lo = 0)
{
return (pick64(val, hi, lo) >> lo);
}

// result<0> to val<N>
static inline u_int64_t pickbit(u_int64_t val, int N)
static inline uint64_t pickbit(uint64_t val, int N)
{
return pickbits64(val, N, N);
}

static inline u_int32_t uimm(u_int32_t val, int hi, int lo)
static inline uint32_t uimm(uint32_t val, int hi, int lo)
{
return pickbits32(val, hi, lo);
}

// SPEC bits(M*N) Replicate(bits(M) x, integer N);
// this is just an educated guess

u_int64_t replicate(u_int64_t bits, int nbits, int count)
uint64_t replicate(uint64_t bits, int nbits, int count)
{
u_int64_t result = 0;
uint64_t result = 0;
// nbits may be 64 in which case we want mask to be -1
u_int64_t mask = ones(nbits);
uint64_t mask = ones(nbits);
for (int i = 0; i < count ; i++) {
result <<= nbits;
result |= (bits & mask);
@@ -140,24 +141,24 @@ u_int64_t replicate(u_int64_t bits, int nbits, int count)
// encoding must be treated as an UNALLOC instruction

// construct a 32 bit immediate value for a logical immediate operation
int expandLogicalImmediate(u_int32_t immN, u_int32_t immr,
u_int32_t imms, u_int64_t &bimm)
int expandLogicalImmediate(uint32_t immN, uint32_t immr,
uint32_t imms, uint64_t &bimm)
{
int len; // ought to be <= 6
u_int32_t levels; // 6 bits
u_int32_t tmask_and; // 6 bits
u_int32_t wmask_and; // 6 bits
u_int32_t tmask_or; // 6 bits
u_int32_t wmask_or; // 6 bits
u_int64_t imm64; // 64 bits
u_int64_t tmask, wmask; // 64 bits
u_int32_t S, R, diff; // 6 bits?
int len; // ought to be <= 6
uint32_t levels; // 6 bits
uint32_t tmask_and; // 6 bits
uint32_t wmask_and; // 6 bits
uint32_t tmask_or; // 6 bits
uint32_t wmask_or; // 6 bits
uint64_t imm64; // 64 bits
uint64_t tmask, wmask; // 64 bits
uint32_t S, R, diff; // 6 bits?

if (immN == 1) {
len = 6; // looks like 7 given the spec above but this cannot be!
} else {
len = 0;
u_int32_t val = (~imms & 0x3f);
uint32_t val = (~imms & 0x3f);
for (int i = 5; i > 0; i--) {
if (val & (1 << i)) {
len = i;
@@ -170,7 +171,7 @@ int expandLogicalImmediate(u_int32_t immN, u_int32_t immr,
// for valid inputs leading 1s in immr must be less than leading
// zeros in imms
int len2 = 0; // ought to be < len
u_int32_t val2 = (~immr & 0x3f);
uint32_t val2 = (~immr & 0x3f);
for (int i = 5; i > 0; i--) {
if (!(val2 & (1 << i))) {
len2 = i;
@@ -199,12 +200,12 @@ int expandLogicalImmediate(u_int32_t immN, u_int32_t immr,

for (int i = 0; i < 6; i++) {
int nbits = 1 << i;
u_int64_t and_bit = pickbit(tmask_and, i);
u_int64_t or_bit = pickbit(tmask_or, i);
u_int64_t and_bits_sub = replicate(and_bit, 1, nbits);
u_int64_t or_bits_sub = replicate(or_bit, 1, nbits);
u_int64_t and_bits_top = (and_bits_sub << nbits) | ones(nbits);
u_int64_t or_bits_top = (0 << nbits) | or_bits_sub;
uint64_t and_bit = pickbit(tmask_and, i);
uint64_t or_bit = pickbit(tmask_or, i);
uint64_t and_bits_sub = replicate(and_bit, 1, nbits);
uint64_t or_bits_sub = replicate(or_bit, 1, nbits);
uint64_t and_bits_top = (and_bits_sub << nbits) | ones(nbits);
uint64_t or_bits_top = (0 << nbits) | or_bits_sub;

tmask = ((tmask
& (replicate(and_bits_top, 2 * nbits, 32 / nbits)))
@@ -218,12 +219,12 @@ int expandLogicalImmediate(u_int32_t immN, u_int32_t immr,

for (int i = 0; i < 6; i++) {
int nbits = 1 << i;
u_int64_t and_bit = pickbit(wmask_and, i);
u_int64_t or_bit = pickbit(wmask_or, i);
u_int64_t and_bits_sub = replicate(and_bit, 1, nbits);
u_int64_t or_bits_sub = replicate(or_bit, 1, nbits);
u_int64_t and_bits_top = (ones(nbits) << nbits) | and_bits_sub;
u_int64_t or_bits_top = (or_bits_sub << nbits) | 0;
uint64_t and_bit = pickbit(wmask_and, i);
uint64_t or_bit = pickbit(wmask_or, i);
uint64_t and_bits_sub = replicate(and_bit, 1, nbits);
uint64_t or_bits_sub = replicate(or_bit, 1, nbits);
uint64_t and_bits_top = (ones(nbits) << nbits) | and_bits_sub;
uint64_t or_bits_top = (or_bits_sub << nbits) | 0;

wmask = ((wmask
& (replicate(and_bits_top, 2 * nbits, 32 / nbits)))
@@ -248,9 +249,9 @@ static void initLITables()
{
li_table_entry_count = 0;
for (unsigned index = 0; index < LI_TABLE_SIZE; index++) {
u_int32_t N = uimm(index, 12, 12);
u_int32_t immr = uimm(index, 11, 6);
u_int32_t imms = uimm(index, 5, 0);
uint32_t N = uimm(index, 12, 12);
uint32_t immr = uimm(index, 11, 6);
uint32_t imms = uimm(index, 5, 0);
if (expandLogicalImmediate(N, immr, imms, LITable[index])) {
InverseLITable[li_table_entry_count].immediate = LITable[index];
InverseLITable[li_table_entry_count].encoding = index;
@@ -264,12 +265,12 @@ static void initLITables()

// public APIs provided for logical immediate lookup and reverse lookup

u_int64_t logical_immediate_for_encoding(u_int32_t encoding)
uint64_t logical_immediate_for_encoding(uint32_t encoding)
{
return LITable[encoding];
}

u_int32_t encoding_for_logical_immediate(u_int64_t immediate)
uint32_t encoding_for_logical_immediate(uint64_t immediate)
{
struct li_pair pair;
struct li_pair *result;
@@ -293,15 +294,15 @@ u_int32_t encoding_for_logical_immediate(u_int64_t immediate)
// fpimm[3:0] = fraction (assuming leading 1)
// i.e. F = s * 1.f * 2^(e - b)

u_int64_t fp_immediate_for_encoding(u_int32_t imm8, int is_dp)
uint64_t fp_immediate_for_encoding(uint32_t imm8, int is_dp)
{
union {
float fpval;
double dpval;
u_int64_t val;
uint64_t val;
};

u_int32_t s, e, f;
uint32_t s, e, f;
s = (imm8 >> 7 ) & 0x1;
e = (imm8 >> 4) & 0x7;
f = imm8 & 0xf;
@@ -329,7 +330,7 @@ u_int64_t fp_immediate_for_encoding(u_int32_t imm8, int is_dp)
return val;
}

u_int32_t encoding_for_fp_immediate(float immediate)
uint32_t encoding_for_fp_immediate(float immediate)
{
// given a float which is of the form
//
@@ -341,10 +342,10 @@ u_int32_t encoding_for_fp_immediate(float immediate)

union {
float fpval;
u_int32_t val;
uint32_t val;
};
fpval = immediate;
u_int32_t s, r, f, res;
uint32_t s, r, f, res;
// sign bit is 31
s = (val >> 31) & 0x1;
// exponent is bits 30-23 but we only want the bottom 3 bits
@@ -46,9 +46,9 @@
* encoding then a map lookup will return 0xffffffff.
*/

u_int64_t logical_immediate_for_encoding(u_int32_t encoding);
u_int32_t encoding_for_logical_immediate(u_int64_t immediate);
u_int64_t fp_immediate_for_encoding(u_int32_t imm8, int is_dp);
u_int32_t encoding_for_fp_immediate(float immediate);
uint64_t logical_immediate_for_encoding(uint32_t encoding);
uint32_t encoding_for_logical_immediate(uint64_t immediate);
uint64_t fp_immediate_for_encoding(uint32_t imm8, int is_dp);
uint32_t encoding_for_fp_immediate(float immediate);

#endif // _IMMEDIATE_H

1 comment on commit 5ce46d9

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 5ce46d9 Aug 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.