Skip to content

Commit 37e4d45

Browse files
[RISC-V] Fix RISC-V Windows build (#114292)
* Fix RISC-V Windows build Also, convert some asserts in `emitDispDataSec` to `printf`: we generally don't want asserts in debug printing code, and I was hitting some of these when disassembling some RISC-V code. * Fix formatting
1 parent 367e0a8 commit 37e4d45

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

src/coreclr/jit/emit.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8469,15 +8469,21 @@ void emitter::emitDispDataSec(dataSecDsc* section, BYTE* dst)
84698469
switch (data->dsDataType)
84708470
{
84718471
case TYP_FLOAT:
8472-
assert(data->dsSize >= 4);
8472+
if (data->dsSize < 4)
8473+
{
8474+
printf("\t<Unexpected data size %d (expected >= 4)\n", data->dsSize);
8475+
}
84738476
printf("\tdd\t%08llXh\t", (UINT64) * reinterpret_cast<uint32_t*>(&data->dsCont[i]));
84748477
printf("\t; %9.6g",
84758478
FloatingPointUtils::convertToDouble(*reinterpret_cast<float*>(&data->dsCont[i])));
84768479
i += 4;
84778480
break;
84788481

84798482
case TYP_DOUBLE:
8480-
assert(data->dsSize >= 8);
8483+
if (data->dsSize < 8)
8484+
{
8485+
printf("\t<Unexpected data size %d (expected >= 8)\n", data->dsSize);
8486+
}
84818487
printf("\tdq\t%016llXh", *reinterpret_cast<uint64_t*>(&data->dsCont[i]));
84828488
printf("\t; %12.9g", *reinterpret_cast<double*>(&data->dsCont[i]));
84838489
i += 8;
@@ -8498,7 +8504,10 @@ void emitter::emitDispDataSec(dataSecDsc* section, BYTE* dst)
84988504
break;
84998505

85008506
case 2:
8501-
assert((data->dsSize % 2) == 0);
8507+
if ((data->dsSize % 2) != 0)
8508+
{
8509+
printf("\t<Unexpected data size %d (expected size%%2 == 0)\n", data->dsSize);
8510+
}
85028511
printf("\tdw\t%04Xh", *reinterpret_cast<uint16_t*>(&data->dsCont[i]));
85038512
for (j = 2; j < 24; j += 2)
85048513
{
@@ -8511,7 +8520,10 @@ void emitter::emitDispDataSec(dataSecDsc* section, BYTE* dst)
85118520

85128521
case 12:
85138522
case 4:
8514-
assert((data->dsSize % 4) == 0);
8523+
if ((data->dsSize % 4) != 0)
8524+
{
8525+
printf("\t<Unexpected data size %d (expected size%%4 == 0)\n", data->dsSize);
8526+
}
85158527
printf("\tdd\t%08Xh", *reinterpret_cast<uint32_t*>(&data->dsCont[i]));
85168528
for (j = 4; j < 24; j += 4)
85178529
{
@@ -8526,7 +8538,10 @@ void emitter::emitDispDataSec(dataSecDsc* section, BYTE* dst)
85268538
case 32:
85278539
case 16:
85288540
case 8:
8529-
assert((data->dsSize % 8) == 0);
8541+
if ((data->dsSize % 8) != 0)
8542+
{
8543+
printf("\t<Unexpected data size %d (expected size%%8 == 0)\n", data->dsSize);
8544+
}
85308545
printf("\tdq\t%016llXh", *reinterpret_cast<uint64_t*>(&data->dsCont[i]));
85318546
for (j = 8; j < 64; j += 8)
85328547
{
@@ -8538,7 +8553,7 @@ void emitter::emitDispDataSec(dataSecDsc* section, BYTE* dst)
85388553
break;
85398554

85408555
default:
8541-
assert(!"unexpected elemSize");
8556+
printf("\t<Unexpected elemSize %d)\n", elemSize);
85428557
break;
85438558
}
85448559
}

src/coreclr/jit/emitriscv64.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,10 +1376,10 @@ void emitter::emitLoadImmediate(emitAttr size, regNumber reg, ssize_t imm)
13761376
insCountLimit = absMaxInsCount;
13771377
}
13781378

1379-
bool utilizeSRLI = false;
1380-
int srliShiftAmount;
1381-
uint64_t originalImm = imm;
1382-
bool cond1 = (y - x) > 31;
1379+
bool utilizeSRLI = false;
1380+
int srliShiftAmount = 0;
1381+
uint64_t originalImm = imm;
1382+
bool cond1 = (y - x) > 31;
13831383
if ((((uint64_t)imm >> 63) & 0b1) == 0 && cond1)
13841384
{
13851385
srliShiftAmount = BitOperations::LeadingZeroCount((uint64_t)imm);
@@ -1429,8 +1429,8 @@ void emitter::emitLoadImmediate(emitAttr size, regNumber reg, ssize_t imm)
14291429
* See the following discussion:
14301430
* https://github.com/dotnet/runtime/pull/113250#discussion_r1987576070 */
14311431

1432-
uint32_t offset1 = imm & WordMask(x);
1433-
uint32_t offset2 = (~(offset1 - 1)) & WordMask(x);
1432+
uint32_t offset1 = imm & WordMask((uint8_t)x);
1433+
uint32_t offset2 = (~(offset1 - 1)) & WordMask((uint8_t)x);
14341434
uint32_t offset = offset1;
14351435
bool isSubtractMode = false;
14361436

@@ -1440,8 +1440,8 @@ void emitter::emitLoadImmediate(emitAttr size, regNumber reg, ssize_t imm)
14401440
* Since adding 1 to it will change the sign bit. Instead, shift x and y
14411441
* to the left by one. */
14421442
int newX = x + 1;
1443-
uint32_t newOffset1 = imm & WordMask(newX);
1444-
uint32_t newOffset2 = (~(newOffset1 - 1)) & WordMask(newX);
1443+
uint32_t newOffset1 = imm & WordMask((uint8_t)newX);
1444+
uint32_t newOffset2 = (~(newOffset1 - 1)) & WordMask((uint8_t)newX);
14451445
if (newOffset2 < offset1)
14461446
{
14471447
x = newX;
@@ -1493,7 +1493,7 @@ void emitter::emitLoadImmediate(emitAttr size, regNumber reg, ssize_t imm)
14931493

14941494
int chunkLsbPos = (x < 11) ? 0 : (x - 11);
14951495
int shift = (x < 11) ? x : 11;
1496-
int chunkMask = (x < 11) ? WordMask(x) : WordMask(11);
1496+
int chunkMask = (x < 11) ? WordMask((uint8_t)x) : WordMask(11);
14971497
while (true)
14981498
{
14991499
uint32_t chunk = (offset >> chunkLsbPos) & chunkMask;
@@ -1522,7 +1522,7 @@ void emitter::emitLoadImmediate(emitAttr size, regNumber reg, ssize_t imm)
15221522
if (isSubtractMode)
15231523
{
15241524
ins[numberOfInstructions - 1] = INS_addi;
1525-
values[numberOfInstructions - 1] = -chunk;
1525+
values[numberOfInstructions - 1] = -(int32_t)chunk;
15261526
}
15271527
else
15281528
{

0 commit comments

Comments
 (0)