Skip to content

Commit 0c843d3

Browse files
authored
Merge pull request #42 from soxfox42/arm64_sign
Signedness for arm64
2 parents 69ea987 + 32c0c17 commit 0c843d3

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

source/backends/arm64.d

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,25 @@ class BackendARM64 : CompilerBackend {
387387
output ~= "ldr x9, [x9]\n";
388388
}
389389

390-
switch (size) {
391-
case 1: output ~= format("ldrb w9, [x9, #%d]\n", offset); break;
392-
case 2: output ~= format("ldrh w9, [x9, #%d]\n", offset); break;
393-
case 4: output ~= format("ldr w9, [x9, #%d]\n", offset); break;
394-
case 8: output ~= format("ldr x9, [x9, #%d]\n", offset); break;
395-
default: Error(node.error, "Bad variable type size");
390+
if (var.type.isSigned) {
391+
switch (size) {
392+
case 1: output ~= format("ldrsb x9, [x9, #%d]\n", offset); break;
393+
case 2: output ~= format("ldrsh x9, [x9, #%d]\n", offset); break;
394+
case 4: output ~= format("ldrsw x9, [x9, #%d]\n", offset); break;
395+
case 8: output ~= format("ldr x9, [x9, #%d]\n", offset); break;
396+
default: Error(node.error, "Bad variable type size");
397+
}
396398
}
397-
399+
else {
400+
switch (size) {
401+
case 1: output ~= format("ldrb w9, [x9, #%d]\n", offset); break;
402+
case 2: output ~= format("ldrh w9, [x9, #%d]\n", offset); break;
403+
case 4: output ~= format("ldr w9, [x9, #%d]\n", offset); break;
404+
case 8: output ~= format("ldr x9, [x9, #%d]\n", offset); break;
405+
default: Error(node.error, "Bad variable type size");
406+
}
407+
}
408+
398409
output ~= "str x9, [x19], #8\n";
399410
}
400411

@@ -415,12 +426,23 @@ class BackendARM64 : CompilerBackend {
415426
base = "x20";
416427
}
417428

418-
switch (size) {
419-
case 1: output ~= format("ldrb w9, [%s, #%d]\n", base, offset); break;
420-
case 2: output ~= format("ldrh w9, [%s, #%d]\n", base, offset); break;
421-
case 4: output ~= format("ldr w9, [%s, #%d]\n", base, offset); break;
422-
case 8: output ~= format("ldr x9, [%s, #%d]\n", base, offset); break;
423-
default: Error(node.error, "Bad variable type size");
429+
if (var.type.isSigned) {
430+
switch (size) {
431+
case 1: output ~= format("ldrsb x9, [%s, #%d]\n", base, offset); break;
432+
case 2: output ~= format("ldrsh x9, [%s, #%d]\n", base, offset); break;
433+
case 4: output ~= format("ldrsw x9, [%s, #%d]\n", base, offset); break;
434+
case 8: output ~= format("ldr x9, [%s, #%d]\n", base, offset); break;
435+
default: Error(node.error, "Bad variable type size");
436+
}
437+
}
438+
else {
439+
switch (size) {
440+
case 1: output ~= format("ldrb w9, [%s, #%d]\n", base, offset); break;
441+
case 2: output ~= format("ldrh w9, [%s, #%d]\n", base, offset); break;
442+
case 4: output ~= format("ldr w9, [%s, #%d]\n", base, offset); break;
443+
case 8: output ~= format("ldr x9, [%s, #%d]\n", base, offset); break;
444+
default: Error(node.error, "Bad variable type size");
445+
}
424446
}
425447

426448
output ~= "str x9, [x19], #8\n";

0 commit comments

Comments
 (0)