24
24
25
25
using namespace avian ::util;
26
26
27
+ namespace {
28
+
29
+ int64_t
30
+ signExtend (unsigned size, int64_t v)
31
+ {
32
+ if (size == 4 ) {
33
+ return static_cast <int32_t >(v);
34
+ } else if (size == 2 ) {
35
+ return static_cast <int16_t >(v);
36
+ } else if (size == 1 ) {
37
+ return static_cast <int8_t >(v);
38
+ } else {
39
+ return v;
40
+ }
41
+ }
42
+
43
+ } // namespace
44
+
27
45
namespace avian {
28
46
namespace codegen {
29
47
namespace x86 {
@@ -328,11 +346,7 @@ void moveCR2(Context* c, UNUSED unsigned aSize, lir::Constant* a,
328
346
UNUSED unsigned bSize, lir::Register* b, unsigned promiseOffset)
329
347
{
330
348
if (vm::TargetBytesPerWord == 4 and bSize == 8 ) {
331
- int64_t v = a->value ->value ();
332
-
333
- if (aSize == 4 ) {
334
- v = static_cast <int32_t >(v);
335
- }
349
+ int64_t v = signExtend (aSize, a->value ->value ());
336
350
337
351
ResolvedPromise high ((v >> 32 ) & 0xFFFFFFFF );
338
352
lir::Constant ah (&high);
@@ -348,13 +362,7 @@ void moveCR2(Context* c, UNUSED unsigned aSize, lir::Constant* a,
348
362
maybeRex (c, vm::TargetBytesPerWord, b);
349
363
opcode (c, 0xb8 + regCode (b));
350
364
if (a->value ->resolved ()) {
351
- int64_t v = a->value ->value ();
352
-
353
- if (aSize == 4 and bSize == 8 ) {
354
- v = static_cast <int32_t >(v);
355
- }
356
-
357
- c->code .appendTargetAddress (v);
365
+ c->code .appendTargetAddress (signExtend (aSize, a->value ->value ()));
358
366
} else {
359
367
expect (c, aSize == vm::TargetBytesPerWord);
360
368
0 commit comments