Skip to content

Commit

Permalink
Merge branch 'dev' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoNasci authored Sep 20, 2024
2 parents 401e5a7 + 7cdc15a commit 54ca8da
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:

- name: Setup mold
if: ${{ matrix.cfg.mold == 'yes' }}
uses: rui314/setup-mold@2e332a0b602c2fc65d2d3995941b1b29a5f554a0 # v1
uses: rui314/setup-mold@0bf4f07ef9048ec62a45f9dbf2f098afa49695f0 # v1

- name: Generate CMake
run: cmake -B build -DDPP_NO_VCPKG=ON -DAVX_TYPE=AVX0 -DCMAKE_BUILD_TYPE=Release ${{matrix.cfg.cmake-flags}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
# Prefix the list here with "+" to use these queries and those in the config file.

- name: Setup mold
uses: rui314/setup-mold@2e332a0b602c2fc65d2d3995941b1b29a5f554a0
uses: rui314/setup-mold@0bf4f07ef9048ec62a45f9dbf2f098afa49695f0

- name: Build
run: cmake -B build -DDPP_NO_VCPKG=ON -DAVX_TYPE=AVX0 -DCMAKE_BUILD_TYPE=Release && cmake --build build -j4
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ jobs:

-
name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
-
name: Login to DockerHub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@15560696de535e4014efeff63c48f16952e52dd1 # v6.2.0
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0
with:
push: true
tags: brainboxdotcc/dpp
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:noble@sha256:2e863c44b718727c860746568e1d54afd13b2fa71b160f5cd9058fc436217b30
FROM ubuntu:noble@sha256:8a37d68f4f73ebf3d4efafbcf66379bf3728902a8038616808f04e34a9ab63ee

RUN apt-get update && apt-get install --no-install-recommends -y libssl-dev zlib1g-dev libsodium-dev libopus-dev cmake pkg-config g++ gcc git make && apt-get clean && rm -rf /var/lib/apt/lists/*

Expand Down
9 changes: 8 additions & 1 deletion cmake/DetectArchitecture.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ include(CheckCXXSourceRuns)
function(check_instruction_set INSTRUCTION_SET_NAME INSTRUCTION_SET_FLAG INSTRUCTION_SET_INTRINSIC)

set(INSTRUCTION_SET_CODE "
#if defined(__arm__) || defined(__aarch64__)
#include <arm_neon.h>
#else
#include <immintrin.h>
#include <stdint.h>
#endif
int main()
{
${INSTRUCTION_SET_INTRINSIC};
Expand All @@ -27,12 +32,14 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
"AVX1?/arch:AVX?__m128i value{}#auto result = _mm_extract_epi32(value, 0)"
"AVX2?/arch:AVX2?__m256i value{}#auto result = _mm256_add_epi32(__m256i{}, __m256i{})"
"AVX512?/arch:AVX512?int32_t result[16]#const _mm512i& value{}#_mm512_store_si512(result, value)"
"AVX1024??uint8x16_t mask{ 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F }#vandq_u8(mask, mask)"
)
else()
set(INSTRUCTION_SETS
"AVX1?-mavx?__m128i value{}#auto result = _mm_extract_epi32(value, 0)"
"AVX2?-mavx2?__m256i value{}#auto result = _mm256_add_epi32(__m256i{}, __m256i{})"
"AVX512?-mavx512f?int32_t result[16]#const _mm512i& value{}#_mm512_store_si512(result, value)"
"AVX1024??uint8x16_t mask{ 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F }#vandq_u8(mask, mask)"
)
endif()

Expand All @@ -43,7 +50,7 @@ set(AVX_TYPE "AVX0" PARENT_SCOPE)
set(AVX_FLAGS "" PARENT_SCOPE)

# This is only supported on x86/x64, it is completely skipped and forced to T_fallback anywhere else
if ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "i386") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64"))
if ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "i386") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64") OR (${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "arm64") OR (${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "armv7l"))

foreach(INSTRUCTION_SET IN LISTS INSTRUCTION_SETS)
string(REPLACE "?" ";" CURRENT_LIST "${INSTRUCTION_SET}")
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/commandhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main() {
/* Command description */
"A test ping command",

/* Guild id (omit for a guild command) */
/* Guild id (omit for a global command) */
819556414099554344
);

Expand Down
2 changes: 1 addition & 1 deletion doxygen-awesome-css
Submodule doxygen-awesome-css updated 1 files
+1 −1 README.md
10 changes: 4 additions & 6 deletions include/dpp/export.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,10 @@ extern bool DPP_EXPORT validate_configuration();

}

#ifndef _WIN32
#define SOCKET int
#else
#ifndef NOMINMAX
#define NOMINMAX
#endif
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif

#include <WinSock2.h>
#endif
Expand Down
118 changes: 118 additions & 0 deletions include/dpp/isa/neon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once

#if defined _MSC_VER || defined __GNUC__ || defined __clang__

#include <arm_neon.h>
#include <numeric>

namespace dpp {

using neon_float = float32x4_t;

/**
* @brief A class for audio mixing operations using ARM NEON instructions.
*/
class audio_mixer {
public:

/**
* @brief The number of 32-bit values per CPU register.
*/
inline static constexpr int32_t byte_blocks_per_register{ 4 };

/**
* @brief Collect a single register worth of data from data_in, apply gain and increment, and store the result in data_out.
* This version uses ARM NEON instructions.
*
* @param data_in Pointer to the input array of int32_t values.
* @param data_out Pointer to the output array of int16_t values.
* @param current_gain The gain to be applied to the elements.
* @param increment The increment value to be added to each element.
*/
inline void collect_single_register(int32_t* data_in, int16_t* data_out, float current_gain, float increment) {
neon_float gathered_values = gather_values(data_in);
neon_float gain_vector = vdupq_n_f32(current_gain);
static constexpr float data[4] = { 0.0f, 1.0f, 2.0f, 3.0f };
neon_float floats = vld1q_f32(data);
neon_float increment_vector = vmulq_f32(vdupq_n_f32(increment), floats));
neon_float current_samples_new = vmulq_f32(gathered_values, vaddq_f32(gain_vector, increment_vector));

// Clamping the values between int16_t min and max
neon_float min_val = vdupq_n_f32(static_cast<float>(std::numeric_limits<int16_t>::min()));
neon_float max_val = vdupq_n_f32(static_cast<float>(std::numeric_limits<int16_t>::max()));

current_samples_new = vmaxq_f32(current_samples_new, min_val);
current_samples_new = vminq_f32(current_samples_new, max_val);

store_values(current_samples_new, data_out);
}

/**
* @brief Combine a register worth of elements from decoded_data and store the result in up_sampled_vector.
* This version uses ARM NEON instructions.
*
* @param up_sampled_vector Pointer to the array of int32_t values.
* @param decoded_data Pointer to the array of int16_t values.
*/
inline void combine_samples(int32_t* up_sampled_vector, const int16_t* decoded_data) {
neon_float up_sampled = gather_values(up_sampled_vector);
neon_float decoded = gather_values(decoded_data);
neon_float newValues = vaddq_f32(up_sampled, decoded);
store_values(newValues, up_sampled_vector);
}

protected:
/**
* @brief Array for storing the values to be loaded/stored.
*/
alignas(16) float values[byte_blocks_per_register]{};

/**
* @brief Stores values from a 128-bit NEON vector to a storage location.
* @tparam value_type The target value type for storage.
* @param values_to_store The 128-bit NEON vector containing values to store.
* @param storage_location Pointer to the storage location.
*/
template<typename value_type> inline void store_values(const neon_float& values_to_store, value_type* storage_location) {
vst1q_f32(values, values_to_store);
for (int64_t x = 0; x < byte_blocks_per_register; ++x) {
storage_location[x] = static_cast<value_type>(values[x]);
}
}

/**
* @brief Specialization for gathering non-float values into a NEON register.
* @tparam value_type The type of values being gathered.
* @return A NEON register containing gathered values.
*/
template<typename value_type> inline neon_float gather_values(value_type* values_new) {
for (uint64_t x = 0; x < byte_blocks_per_register; ++x) {
values[x] = static_cast<float>(values_new[x]);
}
return vld1q_f32(values);
}
};

} // namespace dpp

#endif
4 changes: 3 additions & 1 deletion include/dpp/isa_detection.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
************************************************************************************/
#pragma once

#if AVX_TYPE == 512
#if AVX_TYPE == 1024
#include "isa/neon.h"
#elif AVX_TYPE == 512
#include "isa/avx512.h"
#elif AVX_TYPE == 2
#include "isa/avx2.h"
Expand Down
12 changes: 5 additions & 7 deletions include/dpp/socket.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#pragma once

#ifndef _WIN32
#ifndef SOCKET
#define SOCKET int
#endif
#endif

namespace dpp
{
/**
* @brief Represents a socket file descriptor.
* This is used to ensure parity between windows and unix-like systems.
*/
typedef SOCKET socket;
#ifndef _WIN32
using socket = int;
#else
using socket = SOCKET;
#endif
} // namespace dpp

#ifndef SOCKET_ERROR
Expand Down
2 changes: 1 addition & 1 deletion src/dpp/guild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void from_json(const nlohmann::json& j, guild_member& gm) {
std::string guild_member::get_avatar_url(uint16_t size, const image_type format, bool prefer_animated) const {
if (this->guild_id && this->user_id && !this->avatar.to_string().empty()) {
return utility::cdn_endpoint_url_hash({ i_jpg, i_png, i_webp, i_gif },
"guilds/" + std::to_string(this->guild_id) + "/" + std::to_string(this->user_id), this->avatar.to_string(),
"guilds/" + std::to_string(this->guild_id) + "/users/" + std::to_string(this->user_id) + "/avatars", this->avatar.to_string(),
format, size, prefer_animated, has_animated_guild_avatar());
} else {
return std::string();
Expand Down
2 changes: 1 addition & 1 deletion src/dpp/httpsclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ bool https_client::handle_buffer(std::string &buffer)
case HTTPS_CONTENT:
body += buffer;
buffer.clear();
if (body.length() >= content_length) {
if (content_length == ULLONG_MAX || body.length() >= content_length) {
state = HTTPS_DONE;
this->close();
return false;
Expand Down
1 change: 1 addition & 0 deletions src/dpp/voicestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ bool voicestate::is_suppressed() const {
}

} // namespace dpp

0 comments on commit 54ca8da

Please sign in to comment.