Started trying to optimize MakePixelWaveData

This commit is contained in:
Gabriel Ravier 2020-01-30 14:25:34 +01:00
parent a767c16d83
commit 65db12baaa
3 changed files with 16 additions and 7 deletions

11
src/Attributes.h Normal file
View file

@ -0,0 +1,11 @@
#pragma once
#ifdef __GNUC__
#define ATTRIBUTE_HOT __attribute__((hot))
#else
#define ATTRIBUTE_HOT
#endif

View file

@ -10,17 +10,14 @@
#include "../../Organya.h" #include "../../Organya.h"
#include "../../WindowsWrapper.h" #include "../../WindowsWrapper.h"
#include "../../Attributes.h"
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b))
#define CLAMP(x, y, z) MIN(MAX((x), (y)), (z)) #define CLAMP(x, y, z) MIN(MAX((x), (y)), (z))
#ifdef __GNUC__
#define ATTR_HOT __attribute__((hot))
#else #else
#define ATTR_HOT #define ATTR_HOT
#endif
struct AudioBackend_Sound struct AudioBackend_Sound
{ {
unsigned char *samples; unsigned char *samples;
@ -76,8 +73,8 @@ static void SetSoundPan(AudioBackend_Sound *sound, long pan)
sound->volume_r = sound->pan_r * sound->volume; sound->volume_r = sound->pan_r * sound->volume;
} }
// Most CPU-intensive function in the game (2/3rd CPU time consumption in my experience), so marked with attrHot so the compiler considers it a hot spot (as it is) when optimizing // Most CPU-intensive function in the game, so marked with ATTRIBUTE_HOT so the compiler considers it a hot spot (as it is) when optimizing. This alone can reduce the CPU usage of CSE2 by up to 60%
ATTR_HOT static void MixSounds(float *stream, unsigned int frames_total) ATTRIBUTE_HOT static void MixSounds(float *stream, unsigned int frames_total)
{ {
for (AudioBackend_Sound *sound = sound_list_head; sound != NULL; sound = sound->next) for (AudioBackend_Sound *sound = sound_list_head; sound != NULL; sound = sound->next)
{ {

View file

@ -4,6 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "Attributes.h"
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#include "Random.h" #include "Random.h"
@ -65,7 +66,7 @@ void MakeWaveTables(void)
//BOOL wave_tables_made; //BOOL wave_tables_made;
BOOL MakePixelWaveData(const PIXTONEPARAMETER *ptp, unsigned char *pData) ATTRIBUTE_HOT BOOL MakePixelWaveData(const PIXTONEPARAMETER *ptp, unsigned char *pData)
{ {
int i; int i;
int a, b, c, d; int a, b, c, d;