Skip to content

Commit

Permalink
Getting cache line width using system APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawoodoz committed Feb 1, 2025
1 parent bc69d20 commit d96e9f5
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 76 deletions.
5 changes: 3 additions & 2 deletions Source/DFPSR/api/bufferAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "stringAPI.h"
#include "../implementation/math/scalar.h"
#include "../base/SafePointer.h"
#include "../base/heap.h"

namespace dsr {

Expand All @@ -35,9 +36,9 @@ Buffer buffer_create(intptr_t newSize) {
return handle_createArray<uint8_t>(AllocationInitialization::Zeroed, (uintptr_t)newSize);
}

Buffer buffer_create(intptr_t newSize, int paddToAlignment) {
Buffer buffer_create(intptr_t newSize, uintptr_t paddToAlignment) {
if (newSize < 0) newSize = 0;
if (paddToAlignment > DSR_MAXIMUM_ALIGNMENT) {
if (paddToAlignment > heap_getHeapAlignment()) {
throwError(U"Maximum alignment exceeded when creating a buffer!\n");
return Handle<uint8_t>();
} else {
Expand Down
6 changes: 3 additions & 3 deletions Source/DFPSR/api/bufferAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ namespace dsr {
Buffer buffer_create(intptr_t newSize);

// Allocate a Buffer with padding.
// The buffer always align the start with DSR_MAXIMUM_ALIGNMENT, but this function makes sure that paddToAlignment does not exceed DSR_MAXIMUM_ALIGNMENT.
// Pre-condition: paddToAlignment <= DSR_MAXIMUM_ALIGNMENT
Buffer buffer_create(intptr_t newSize, int paddToAlignment);
// The buffer always align the start with heap alignment, but this function makes sure that paddToAlignment does not exceed heap alignment.
// Pre-condition: paddToAlignment <= heap_getHeapAlignment()
Buffer buffer_create(intptr_t newSize, uintptr_t paddToAlignment);

// Sets the allocation's destructor, to be called when there are no more reference counted pointers to the buffer.
// The destructor is not responsible for freeing the memory allocation itself, only calling destructors in the content.
Expand Down
10 changes: 5 additions & 5 deletions Source/DFPSR/api/fileAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
#include "stringAPI.h"
#include "bufferAPI.h"
#include "../base/Handle.h"
#if defined(WIN32) || defined(_WIN32)
#define USE_MICROSOFT_WINDOWS
#endif
#include "../settings.h"

// The file API exists to save and load buffers of data for any type of file.
// Any file format that is implemented against the Buffer type instead of hardcoding against the file stream can easily be
Expand All @@ -38,12 +36,14 @@
namespace dsr {
// The PathSyntax enum allow processing theoreical paths for other operating systems than the local.
enum class PathSyntax { Windows, Posix };
#ifdef USE_MICROSOFT_WINDOWS
#if defined(USE_MICROSOFT_WINDOWS)
// Let the local syntax be for Windows.
#define LOCAL_PATH_SYNTAX dsr::PathSyntax::Windows
#else
#elif defined(USE_POSIX)
// Let the local syntax be for Posix.
#define LOCAL_PATH_SYNTAX dsr::PathSyntax::Posix
#else
#error "The target platform was not recognized as one of the supported operating systems in the file API!\n"
#endif

// Define NO_IMPLICIT_PATH_SYNTAX before including the header if you want all PathSyntax arguments to be explicit.
Expand Down
2 changes: 1 addition & 1 deletion Source/DFPSR/api/imageAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ IMAGE_TYPE image_create_template(const char * name, int32_t width, int32_t heigh
} else {
static const int32_t pixelSize = image_getPixelSize<IMAGE_TYPE>();
// Calculate the stride.
uintptr_t byteStride = memory_getPaddedSize(width * pixelSize, DSR_MAXIMUM_ALIGNMENT);
uintptr_t byteStride = memory_getPaddedSize(width * pixelSize, heap_getHeapAlignment());
uint32_t pixelStride = byteStride / pixelSize;
// Create the image.
return IMAGE_TYPE(buffer_create(byteStride * height).setName(name), 0, width, height, pixelStride, packOrderIndex);
Expand Down
Loading

0 comments on commit d96e9f5

Please sign in to comment.