Skip to content

Conversation

@ZERICO2005
Copy link
Contributor

@ZERICO2005 ZERICO2005 commented Apr 11, 2025

I've added a few function __atrribute__'s to graphx.h. This can help with optimization, and safety.
Changes:

  • gfx_AllocSprite and gfx_ConvertToNewRLETSprite take a function pointer to a malloc routine, so I've added __nonnull__ to that parameter since these routines do not check if the function pointer is NULL.
  • gfx_Lighten and gfx_Darken are __const__ functions as the same inputs will always generate the same output.
  • gfx_GetTextX, gfx_GetTextY, gfx_GetCharWidth, and gfx_GetStringWidth are __pure__ functions, as they read from non-volatile addresses.
  • A bunch of the sprite routines say @note sprite_in and sprite_out cannot be the same, so I've added __restrict to both parameters, which can then allow the compiler to warn about it.
  • gfx_TilePtr and gfx_TilePtrMapped are __pure__ since they only read from the parameters passed into the function.

Other things that could be done later on:

  • gfx_GetPixel might be __pure__, but that depends on if we consider reading from vram to be volatile or not
  • __nonnull__ could be applied to most sprite routines, as they don't appear to check if the sprite pointer is NULL
  • In the end, graphx.h might look like this with all applicable compiler directives https://github.com/ZERICO2005/toolchain/blob/graphy/src/graphx/graphx.h

@mateoconlechuga mateoconlechuga merged commit 6e58912 into master Apr 11, 2025
9 checks passed
@mateoconlechuga mateoconlechuga deleted the pr/graphx_func_prototype branch April 11, 2025 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants