History

x86-64: Allow loads from some structs/unions

GCC allows register loads for asms based on type mode, and correctly sized structs/union have an allowed mode (basically 1,2,4,8 sized aggregates).

Michael Matz committed 10 years ago

Commit ca8c1cd1 parent 9ae10ca2 files · +22 −0Browse files

Unified · Split

2 files
  1. tests/tcctest.c +6 −0
  2. x86_64-gen.c +16 −0
tests/tcctest.c+6−0
@@ -2677,6 +2677,7 @@ void asm_test(void) · 2676 unmodified lines
26772677 asm block gets the outer one. */
26782678 int base_func = 42;
26792679 void override_func3 (void);
2680+ unsigned long asmret;
26802681
26812682 printf("inline asm:\n");
26822683
@@ -2720,6 +2721,11 @@ void asm_test(void) · 37 unmodified lines
27202721 the global one, not the local decl from this function. */
27212722 asm volatile(".weak override_func3\n.set override_func3, base_func");
27222723 override_func3();
2724+ /* Check that we can also load structs of appropriate layout
2725+ into registers. */
2726+ asm volatile("" : "=r" (asmret) : "0"(s2));
2727+ if (asmret != s2.addr)
2728+ printf("asmstr: failed\n");
27232729 return;
27242730 label1:
27252731 goto label2;
x86_64-gen.c+16−0
@@ -382,6 +382,22 @@ void load(int r, SValue *sv) · 381 unmodified lines
382382 load(fr, &v1);
383383 }
384384 ll = 0;
385+ /* Like GCC we can load from small enough properly sized
386+ structs and unions as well.
387+ XXX maybe move to generic operand handling, but should
388+ occur only with asm, so tccasm.c might also be a better place */
389+ if ((ft & VT_BTYPE) == VT_STRUCT) {
390+ int align;
391+ switch (type_size(&sv->type, &align)) {
392+ case 1: ft = VT_BYTE; break;
393+ case 2: ft = VT_SHORT; break;
394+ case 4: ft = VT_INT; break;
395+ case 8: ft = VT_LLONG; break;
396+ default:
397+ tcc_error("invalid aggregate type for register load");
398+ break;
399+ }
400+ }
385401 if ((ft & VT_BTYPE) == VT_FLOAT) {
386402 b = 0x6e0f66;
387403 r = REG_VALUE(r); /* movd */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t