Skip to content

Conversation

ZERICO2005
Copy link
Contributor

@ZERICO2005 ZERICO2005 commented Sep 6, 2025

calloc (when __TICE__ is defined) now uses an inlined implementation of bzero which uses the $E40000 address to speed up the zero filling of memory.

Otherwise, it will use the previous memset implementation when __TICE__ is undefined.

@ZERICO2005 ZERICO2005 changed the title optimized the zero filling in calloc (__TICE__ only) changed behaviour of malloc(0) and optimized zero filling in calloc Sep 6, 2025
@ZERICO2005 ZERICO2005 changed the title changed behaviour of malloc(0) and optimized zero filling in calloc changed behaviour of malloc(0) and optimized calloc Sep 6, 2025
@runer112 runer112 self-requested a review September 6, 2025 22:31
; inlined memset/bzero
; assumes that malloc(0) returns NULL, so we can skip the check for zero size
add hl, bc
cpd
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it is okay for cpd to read nonnull_ptr_from_malloc + size

@ZERICO2005
Copy link
Contributor Author

ZERICO2005 commented Sep 16, 2025

To reduce the complexity of this PR, I undid the allocator switches to nonzero_fill_calloc when malloc(0) is known to return NULL commits for now (which essentially added 4 different calloc variants). That way we can focus on the two important changes that will be made in this PR:

  • Changing the behavior of __simple_malloc(0) and __standard_malloc(0) to return NULL.
  • Optimizing calloc zero filling by using the $E40000 all zeros address

@ZERICO2005 ZERICO2005 marked this pull request as ready for review September 21, 2025 00:56
@runer112 runer112 self-assigned this Oct 16, 2025
Comment on lines +24 to +28
; test for NULL
add hl, bc
; or a, a ; assumes that ptr + size does not overflow on TICE
sbc hl, bc
pop bc ; BC = size
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this should use calc84maniac's correction to be safe. Also, I suggest removing the reference to the TI-CE, as it's not really relevant to the assumption.

Suggested change
; test for NULL
add hl, bc
; or a, a ; assumes that ptr + size does not overflow on TICE
sbc hl, bc
pop bc ; BC = size
pop bc ; BC = size
; test for NULL
add hl, bc
; or a, a ; assumes that ptr + size does not overflow
sbc hl, bc

@runer112 runer112 removed their assignment Oct 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants