Skip to content

Commit f07f537

Browse files
authored
Update functions.h for better inlining
1 parent b8c1de4 commit f07f537

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

src/deluge/util/functions.h

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern int32_t paramNeutralValues[];
4343

4444
void functionsInit();
4545

46-
static inline void intToString(int32_t number, char* buffer) {
46+
[[gnu::always_inline]] static inline void intToString(int32_t number, char* buffer) {
4747
intToString(number, buffer, 1);
4848
}
4949

@@ -60,7 +60,7 @@ void byteToHex(uint8_t number, char* buffer);
6060
uint8_t hexToByte(char const* firstChar);
6161

6262
// bits must be *less* than 32! I.e. 31 or less
63-
inline int32_t signed_saturate_operand_unknown(int32_t val, int32_t bits) {
63+
[[gnu::always_inline]] inline int32_t signed_saturate_operand_unknown(int32_t val, int32_t bits) {
6464

6565
// Despite having this switch at the per-audio-sample level, it doesn't introduce any slowdown compared to just always saturating by the same amount!
6666
switch (bits) {
@@ -108,28 +108,28 @@ inline int32_t signed_saturate_operand_unknown(int32_t val, int32_t bits) {
108108
}
109109

110110
template <uint8_t lshift>
111-
inline int32_t lshiftAndSaturate(int32_t val) {
111+
[[gnu::always_inline]] inline int32_t lshiftAndSaturate(int32_t val) {
112112
return signed_saturate<32 - lshift>(val) << lshift;
113113
}
114114

115115
// lshift must be greater than 0! Not 0
116-
inline int32_t lshiftAndSaturateUnknown(int32_t val, uint8_t lshift) {
116+
[[gnu::always_inline]] inline int32_t lshiftAndSaturateUnknown(int32_t val, uint8_t lshift) {
117117
return signed_saturate_operand_unknown(val, 32 - lshift) << lshift;
118118
}
119119

120-
constexpr uint32_t charsToIntegerConstant(char a, char b, char c, char d) {
120+
[[gnu::always_inline]] constexpr uint32_t charsToIntegerConstant(char a, char b, char c, char d) {
121121
return (static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | (static_cast<uint32_t>(c) << 16)
122122
| (static_cast<uint32_t>(d) << 24);
123123
}
124124

125-
constexpr uint16_t charsToIntegerConstant(char a, char b) {
125+
[[gnu::always_inline]] constexpr uint16_t charsToIntegerConstant(char a, char b) {
126126
return (static_cast<uint16_t>(a)) | (static_cast<uint16_t>(b) << 8);
127127
}
128128
/**
129129
* replace asterix with a digit
130130
* Only works for single digits
131131
*/
132-
constexpr void asterixToInt(char* str, int32_t i) {
132+
[[gnu::always_inline]] constexpr void asterixToInt(char* str, int32_t i) {
133133
while (*str != 0) {
134134
if (*str == '*') {
135135
*str = (char)('0' + i);
@@ -228,7 +228,7 @@ bool paramNeedsLPF(int32_t p, bool fromAutomation);
228228
int32_t shiftVolumeByDB(int32_t oldValue, float offset);
229229
int32_t quickLog(uint32_t input);
230230

231-
constexpr void convertFloatToIntAtMemoryLocation(uint32_t* pos) {
231+
[[gnu::always_inline]] constexpr void convertFloatToIntAtMemoryLocation(uint32_t* pos) {
232232

233233
//*(int32_t*)pos = *(float*)pos * 2147483648;
234234

@@ -244,7 +244,7 @@ constexpr void convertFloatToIntAtMemoryLocation(uint32_t* pos) {
244244
*pos = outputValue;
245245
}
246246

247-
constexpr int32_t floatToInt(float theFloat) {
247+
[[gnu::always_inline]] constexpr int32_t floatToInt(float theFloat) {
248248
uint32_t readValue = std::bit_cast<uint32_t>(theFloat);
249249
int32_t exponent = (int32_t)((readValue >> 23) & 255) - 127;
250250

@@ -257,7 +257,7 @@ constexpr int32_t floatToInt(float theFloat) {
257257
return outputValue;
258258
}
259259

260-
constexpr int32_t floatBitPatternToInt(uint32_t readValue) {
260+
[[gnu::always_inline]] constexpr int32_t floatBitPatternToInt(uint32_t readValue) {
261261
int32_t exponent = (int32_t)((readValue >> 23) & 255) - 127;
262262

263263
int32_t outputValue = (exponent >= 0) ? 2147483647 : (uint32_t)((readValue << 8) | 0x80000000) >> (-exponent);
@@ -270,7 +270,7 @@ constexpr int32_t floatBitPatternToInt(uint32_t readValue) {
270270
}
271271

272272
// input must not have any extra bits set than numBitsInInput specifies
273-
inline int32_t interpolateTableSigned(uint32_t input, int32_t numBitsInInput, const int16_t* table,
273+
[[gnu::always_inline]] inline int32_t interpolateTableSigned(uint32_t input, int32_t numBitsInInput, const int16_t* table,
274274
int32_t numBitsInTableSize = 8) {
275275
int32_t whichValue = input >> (numBitsInInput - numBitsInTableSize);
276276
int32_t rshiftAmount = numBitsInInput - 16 - numBitsInTableSize;
@@ -290,7 +290,7 @@ uint32_t interpolateTableInverse(int32_t tableValueBig, int32_t numBitsInLookupO
290290

291291
// input must not have any extra bits set than numBitsInInput specifies
292292
// Output of this function (unlike the regular 1d one) is only +- 1073741824
293-
inline int32_t interpolateTableSigned2d(uint32_t inputX, uint32_t inputY, int32_t numBitsInInputX,
293+
[[gnu::always_inline]] inline int32_t interpolateTableSigned2d(uint32_t inputX, uint32_t inputY, int32_t numBitsInInputX,
294294
int32_t numBitsInInputY, const int16_t* table, int32_t numBitsInTableSizeX,
295295
int32_t numBitsInTableSizeY) {
296296

@@ -317,7 +317,7 @@ inline int32_t interpolateTableSigned2d(uint32_t inputX, uint32_t inputY, int32_
317317
}
318318

319319
template <unsigned saturationAmount>
320-
inline int32_t getTanH(int32_t input) {
320+
[[gnu::always_inline]] inline int32_t getTanH(int32_t input) {
321321
uint32_t workingValue;
322322

323323
if (saturationAmount)
@@ -339,7 +339,7 @@ inline int32_t getTanH(int32_t input) {
339339
return interpolateTableSigned(workingValue, 32, tanHSmall, 8) >> (saturationAmount + 2);
340340
}
341341

342-
inline int32_t getTanHAntialiased(int32_t input, uint32_t* lastWorkingValue, uint32_t saturationAmount) {
342+
[[gnu::always_inline]] inline int32_t getTanHAntialiased(int32_t input, uint32_t* lastWorkingValue, uint32_t saturationAmount) {
343343

344344
uint32_t workingValue = (uint32_t)lshiftAndSaturateUnknown(input, saturationAmount) + 2147483648u;
345345

@@ -349,15 +349,15 @@ inline int32_t getTanHAntialiased(int32_t input, uint32_t* lastWorkingValue, uin
349349
return toReturn;
350350
}
351351

352-
inline int32_t getSine(uint32_t phase, uint8_t numBitsInInput = 32) {
352+
[[gnu::always_inline]] inline int32_t getSine(uint32_t phase, uint8_t numBitsInInput = 32) {
353353
return interpolateTableSigned(phase, numBitsInInput, sineWaveSmall, 8);
354354
}
355355

356-
inline int32_t getSquare(uint32_t phase, uint32_t phaseWidth = 2147483648u) {
356+
[[gnu::always_inline]] inline int32_t getSquare(uint32_t phase, uint32_t phaseWidth = 2147483648u) {
357357
return ((phase >= phaseWidth) ? (-2147483648) : 2147483647);
358358
}
359359

360-
inline int32_t getSquareSmall(uint32_t phase, uint32_t phaseWidth = 2147483648u) {
360+
[[gnu::always_inline]] inline int32_t getSquareSmall(uint32_t phase, uint32_t phaseWidth = 2147483648u) {
361361
return ((phase >= phaseWidth) ? (-1073741824) : 1073741823);
362362
}
363363

@@ -367,13 +367,13 @@ inline int32_t getSquareSmall(uint32_t phase, uint32_t phaseWidth = 2147483648u)
367367
phase *= multiplier;
368368
*/
369369

370-
inline int32_t getTriangleSmall(uint32_t phase) {
370+
[[gnu::always_inline]] inline int32_t getTriangleSmall(uint32_t phase) {
371371
if (phase >= 2147483648u)
372372
phase = -phase;
373373
return phase - 1073741824;
374374
}
375375

376-
inline int32_t getTriangle(uint32_t phase) {
376+
[[gnu::always_inline]] inline int32_t getTriangle(uint32_t phase) {
377377
return ((phase < 2147483648u) ? 2 : -2) * phase + 2147483648u;
378378
//return getTriangleSmall(phase) << 1;
379379
}
@@ -388,11 +388,11 @@ int32_t getDecay4(uint32_t input, uint8_t numBitsInInput);
388388

389389
extern uint32_t z, w, jcong;
390390

391-
inline uint8_t getRandom255() {
391+
[[gnu::always_inline]] inline uint8_t getRandom255() {
392392
return CONG >> 24;
393393
}
394394

395-
inline int32_t getNoise() {
395+
[[gnu::always_inline]] inline int32_t getNoise() {
396396
return CONG;
397397
}
398398

@@ -503,14 +503,14 @@ inline void colorCopy(uint8_t* dest, uint8_t* src, uint8_t intensity, uint8_t br
503503
dest[2] = (uint8_t)((src[2] * intensity / 255) / brightnessDivider);
504504
}
505505

506-
inline int32_t increaseMagnitude(int32_t number, int32_t magnitude) {
506+
[[gnu::always_inline]] inline int32_t increaseMagnitude(int32_t number, int32_t magnitude) {
507507
if (magnitude >= 0)
508508
return number << magnitude;
509509
else
510510
return number >> (-magnitude);
511511
}
512512

513-
inline int32_t increaseMagnitudeAndSaturate(int32_t number, int32_t magnitude) {
513+
[[gnu::always_inline]] inline int32_t increaseMagnitudeAndSaturate(int32_t number, int32_t magnitude) {
514514
if (magnitude > 0)
515515
return lshiftAndSaturateUnknown(number, magnitude);
516516
else
@@ -524,27 +524,27 @@ int32_t divide_round_negative(int32_t dividend, int32_t divisor);
524524
void dissectIterationDependence(int32_t probability, int32_t* getDivisor, int32_t* getWhichIterationWithinDivisor);
525525
int32_t encodeIterationDependence(int32_t divisor, int32_t iterationWithinDivisor);
526526

527-
inline uint32_t swapEndianness32(uint32_t input) {
527+
[[gnu::always_inline]] inline uint32_t swapEndianness32(uint32_t input) {
528528
int32_t out;
529529
asm("rev %0, %1" : "=r"(out) : "r"(input));
530530
return out;
531531
}
532532

533-
inline uint32_t swapEndianness2x16(uint32_t input) {
533+
[[gnu::always_inline]] inline uint32_t swapEndianness2x16(uint32_t input) {
534534
int32_t out;
535535
asm("rev16 %0, %1" : "=r"(out) : "r"(input));
536536
return out;
537537
}
538538

539-
inline int32_t getMagnitudeOld(uint32_t input) {
539+
[[gnu::always_inline]] inline int32_t getMagnitudeOld(uint32_t input) {
540540
return 32 - clz(input);
541541
}
542542

543-
inline int32_t getMagnitude(uint32_t input) {
543+
[[gnu::always_inline]] inline int32_t getMagnitude(uint32_t input) {
544544
return 31 - clz(input);
545545
}
546546

547-
inline bool isPowerOfTwo(uint32_t input) {
547+
[[gnu::always_inline]] inline bool isPowerOfTwo(uint32_t input) {
548548
return (input == 1 << getMagnitude(input));
549549
}
550550

@@ -560,12 +560,12 @@ void getNoteLengthNameFromMagnitude(char* text, int32_t magnitude, bool clarifyP
560560
bool doesFilenameFitPrefixFormat(char const* fileName, char const* filePrefix, int32_t prefixLength);
561561
int32_t fresultToDelugeErrorCode(FRESULT result);
562562

563-
inline void writeInt16(char** address, uint16_t number) {
563+
[[gnu::always_inline]] inline void writeInt16(char** address, uint16_t number) {
564564
*(uint16_t*)*address = number;
565565
*address += 2;
566566
}
567567

568-
inline void writeInt32(char** address, uint32_t number) {
568+
[[gnu::always_inline]] inline void writeInt32(char** address, uint32_t number) {
569569
*(uint32_t*)*address = number;
570570
*address += 4;
571571
}

0 commit comments

Comments
 (0)