Skip to content

COMPILER: Initializing a struct to 0 causes the compiler to emit a bit zero array and do a memcpy #4

@ruifig

Description

@ruifig

Imagine I have this in the stack:

u32 ownTlsSlots[TLS_MAXSLOTS*1024] = { 0 };

I was expecting the compiler to emit a memset.
Instead it does this:

	; Memcopy 
	lea ip, [.L7]; Line 1560
	sub r1, fp, 32768; Line 1550
	mov r0, 32768 ; Copy size
	memcpy [r1], [ip], r0

and

.rodata
.L7:
	.word 0
	.zero	32764

I was expecting the compiler to just generate a memset.
I'm not sure if the problem is compiler or something in my compiler backend.

Maybe it can be improved by looking at the ASSIGN operations. VBCC's documentation says this:

#define ASSIGN 2
Copy q1 to z. q1->z.
q2.val.vmax contains the size of the objects (this is necessary if it is an array
or a struct). It should be accessed using the opsize()-macro. typf does not
have to be an elementary type!
The only case where typf == ARRAY should be in automatic initializations.
It is also possible that (typf&NQ) == CHAR but the size is != 1. This is created
for an inline memcpy/strcpy where the type is not known.

Once this is fixed, remove the createZeroed macro from the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions