From b1d013977fe401e584fa163b2b91d4880b19cfa2 Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Sun, 26 Apr 2026 17:50:21 +0200 Subject: [PATCH] Add compiler intrinsic support functions for 64-bit arithmetic --- xtoskrnl/CMakeLists.txt | 1 + xtoskrnl/rtl/amd64/intrin.cc | 10 +++ xtoskrnl/rtl/i686/intrin.cc | 162 +++++++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 xtoskrnl/rtl/amd64/intrin.cc create mode 100644 xtoskrnl/rtl/i686/intrin.cc diff --git a/xtoskrnl/CMakeLists.txt b/xtoskrnl/CMakeLists.txt index bc59fd9..39a6cb1 100644 --- a/xtoskrnl/CMakeLists.txt +++ b/xtoskrnl/CMakeLists.txt @@ -75,6 +75,7 @@ list(APPEND XTOSKRNL_SOURCE ${XTOSKRNL_SOURCE_DIR}/po/idle.cc ${XTOSKRNL_SOURCE_DIR}/rtl/${ARCH}/dispatch.cc ${XTOSKRNL_SOURCE_DIR}/rtl/${ARCH}/exsup.cc + ${XTOSKRNL_SOURCE_DIR}/rtl/${ARCH}/intrin.cc ${XTOSKRNL_SOURCE_DIR}/rtl/atomic.cc ${XTOSKRNL_SOURCE_DIR}/rtl/bitmap.cc ${XTOSKRNL_SOURCE_DIR}/rtl/data.cc diff --git a/xtoskrnl/rtl/amd64/intrin.cc b/xtoskrnl/rtl/amd64/intrin.cc new file mode 100644 index 0000000..5fc979f --- /dev/null +++ b/xtoskrnl/rtl/amd64/intrin.cc @@ -0,0 +1,10 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/rtl/amd64/intrin.cc + * DESCRIPTION: Compiler intrinsic support routines + * DEVELOPERS: Aiken Harris + */ + +#include + diff --git a/xtoskrnl/rtl/i686/intrin.cc b/xtoskrnl/rtl/i686/intrin.cc new file mode 100644 index 0000000..bddd45a --- /dev/null +++ b/xtoskrnl/rtl/i686/intrin.cc @@ -0,0 +1,162 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/rtl/i686/intrin.cc + * DESCRIPTION: Compiler intrinsic support routines + * DEVELOPERS: Aiken Harris + */ + +#include + + + +/** + * Divides a 64-bit signed integer by a 64-bit signed integer. + * + * @param Dividend + * Supplies the 64-bit signed dividend. + * + * @param Divisor + * Supplies the 64-bit signed divisor. + * + * @return This routine returns the 64-bit signed quotient. + * + * @since XT 1.0 + */ +XTCLINK +XTCDECL +LONGLONG +_alldiv(IN LONGLONG Dividend, + IN LONGLONG Divisor) +{ + /* Call the internal signed division routine and return the quotient */ + return RTL::Math::Divide64(Dividend, Divisor, NULLPTR); +} + +/** + * Divides a 64-bit signed integer by a 64-bit signed integer and retrieves the remainder. + * + * @param Dividend + * Supplies the 64-bit signed dividend. + * + * @param Divisor + * Supplies the 64-bit signed divisor. + * + * @param Remainder + * Supplies a pointer to a variable that receives the 64-bit signed remainder. + * + * @return This routine returns the 64-bit signed quotient. + * + * @since XT 1.0 + */ +XTCLINK +XTCDECL +LONGLONG +_alldvrm(IN LONGLONG Dividend, + IN LONGLONG Divisor, + OUT PLONGLONG Remainder) +{ + /* Call the internal signed division routine to compute both quotient and remainder */ + return RTL::Math::Divide64(Dividend, Divisor, Remainder); +} +/** + * Calculates the remainder of a 64-bit signed integer division. + * + * @param Dividend + * Supplies the 64-bit signed dividend. + * + * @param Divisor + * Supplies the 64-bit signed divisor. + * + * @return This routine returns the 64-bit signed remainder. + * + * @since XT 1.0 + */ +XTCLINK +XTCDECL +LONGLONG +_allrem(IN LONGLONG Dividend, + IN LONGLONG Divisor) +{ + LONGLONG Remainder; + + /* Call the internal signed division routine and return the computed remainder */ + RTL::Math::Divide64(Dividend, Divisor, &Remainder); + return Remainder; +} + +/** + * Divides a 64-bit unsigned integer by a 64-bit unsigned integer. + * + * @param Dividend + * Supplies the 64-bit unsigned dividend. + * + * @param Divisor + * Supplies the 64-bit unsigned divisor. + * + * @return This routine returns the 64-bit unsigned quotient. + * + * @since XT 1.0 + */ +XTCLINK +XTCDECL +ULONGLONG +_aulldiv(IN ULONGLONG Dividend, + IN ULONGLONG Divisor) +{ + /* Call the internal unsigned division routine and return the quotient */ + return RTL::Math::DivideUnsigned64(Dividend, Divisor, NULLPTR); +} + +/** + * Divides a 64-bit unsigned integer by a 64-bit unsigned integer and retrieves the remainder. + * + * @param Dividend + * Supplies the 64-bit unsigned dividend. + * + * @param Divisor + * Supplies the 64-bit unsigned divisor. + * + * @param Remainder + * Supplies a pointer to a variable that receives the 64-bit unsigned remainder. + * + * @return This routine returns the 64-bit unsigned quotient. + * + * @since XT 1.0 + */ +XTCLINK +XTCDECL +ULONGLONG +_aulldvrm(ULONGLONG Dividend, + ULONGLONG Divisor, + PULONGLONG Remainder) +{ + /* Call the internal unsigned division routine to compute both quotient and remainder */ + return RTL::Math::DivideUnsigned64(Dividend, Divisor, Remainder); +} + +/** + * Calculates the remainder of a 64-bit unsigned integer division. + * + * @param Dividend + * Supplies the 64-bit unsigned dividend. + * + * @param Divisor + * Supplies the 64-bit unsigned divisor. + * + * @return This routine returns the 64-bit unsigned remainder. + * + * @since XT 1.0 + */ +XTCLINK +XTCDECL +ULONGLONG +_aullrem(IN ULONGLONG Dividend, + IN ULONGLONG Divisor) +{ + ULONGLONG Remainder; + + /* Call the internal unsigned division routine and return the computed remainder */ + RTL::Math::DivideUnsigned64(Dividend, Divisor, &Remainder); + return Remainder; +}