diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | CHANGELOG.txt | 9 | ||||
-rw-r--r-- | CMakeLists.txt | 26 | ||||
-rwxr-xr-x | getTarget.sh | 10 | ||||
-rwxr-xr-x | install.sh | 38 | ||||
-rw-r--r-- | rttest.cc | 2 | ||||
-rw-r--r-- | u8c.svg | 28 | ||||
-rw-r--r-- | u8c_boxes.svg | 23 | ||||
-rw-r--r-- | u8c_braille.svg | 23 | ||||
-rw-r--r-- | zp/CMakeLists.txt | 150 | ||||
-rw-r--r-- | zp/GNUmakefile | 267 | ||||
-rw-r--r-- | zp/source/amd64/bs/syscl.s | 46 | ||||
-rw-r--r-- | zp/source/amd64/bs/trp.s | 10 | ||||
-rw-r--r-- | zp/source/amd64/mem/memcpy.s | 86 | ||||
-rw-r--r-- | zp/source/amd64/mem/memfil.s | 44 | ||||
-rw-r--r-- | zp/source/any/bs/syscl.cc (renamed from zp/source/any/bs/syscl.c) | 6 | ||||
-rw-r--r-- | zp/source/any/bs/trp.cc (renamed from zp/source/any/bs/trp.c) | 4 |
17 files changed, 454 insertions, 321 deletions
@@ -1,3 +1,6 @@ +*.a +*.o +*.so /build /install /test diff --git a/CHANGELOG.txt b/CHANGELOG.txt index fb9e68a..c0e56a1 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -44,6 +44,15 @@ * Remove build artefacts; * Rebase (post-zp commits only); +* Implement remaining C functions in C++; +* Use NASM on AMD64; +* Remove build artefacts; +* Switch back to GNU Make; +* Add u8c logos; +* Remove installation script; +* Update target detection script; +* Update gitingore; + # 0.0.2 * Migrate to CMake; diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 3ddb60e..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -cmake_minimum_required(VERSION 3.17) - -set(ZP_ENABLE_SYSTEM_CALLS False CACHE BOOL "Disable the syscl function (False|True).") -set(ZP_LIBRARY_TYPE "Static" CACHE STRING "Type of library file (Static|Shared).") -set(ZP_TARGET "Any" CACHE STRING "Target of the library (Any or Amd64|Arm|Arm64|Ia32).") - -if("${ZP_LIBRARY_TYPE}" STREQUAL "Static") - set(ZP_LIBRARY_TYPE_VALUE STATIC) -elseif("${ZP_LIBRARY_TYPE}" STREQUAL "Shared") -set(ZP_LIBRARY_TYPE_VALUE SHARED) -else() - message(FATAL_ERROR "Library type \"${ZP_LIBRARY_TYPE}\" is invalid") -endif() - -message(STATUS "Building ${ZP_LIBRARY_TYPE} library") -message(STATUS "Targeting ${ZP_TARGET}") - -project( - zp - - VERSION 0.0.2 - HOMEPAGE_URL "https://mandelbrot.dk/zp" - LANGUAGES C CXX ASM -) - -add_subdirectory(zp) diff --git a/getTarget.sh b/getTarget.sh index 3530ee1..897b2e2 100755 --- a/getTarget.sh +++ b/getTarget.sh @@ -4,16 +4,16 @@ machine="$(uname -m)" if [ "${machine}" == "x64" ] || [ "${machine}" == "x86_64" ] then - printf "Amd64" + printf "amd64" elif [ "${machine}" == "arm" ] then - printf "Arm" + printf "arm" elif [ "${machine}" == "aarch64" ] || [ "${machine}" == "aarch64_be" ] || [ "${machine}" == "arm64" ] || [ "${machine}" == "armv8b" ] || [ "${machine}" == "armv8l" ] then - printf "Arm64" + printf "arm64" elif [ "${machine}" == "i386" ] || [ "${machine}" == "i686" ] || [ "${machine}" == "x86" ] then - printf "Ia32" + printf "ia32" else - printf "Any" + printf "any" fi diff --git a/install.sh b/install.sh deleted file mode 100755 index abe08ca..0000000 --- a/install.sh +++ /dev/null @@ -1,38 +0,0 @@ -blddir="${1}" -hdrdir="${2}" -libdir="${3}" - -if [ -z "${blddir}" ] -then - echo "Build directory not set!" - exit 1 -fi - -if [ -z "${hdrdir}" ] -then - echo "Header directory not set!" - exit 1 -fi - -if [ -z "${libdir}" ] -then - echo "Library directory not set!" - exit 1 -fi - -mkdir -pvm755 "${hdrdir}/zp/priv" -mkdir -pvm755 "${hdrdir}/zp/"{"bs","mem","str"}".d" -mkdir -pvm755 "${hdrdir}/zp/mth.d/"{"pair","vec2","vec3","vec4"} -mkdir -pvm755 "${libdir}" - -install -vm644 "zp/include/zp/"{"bs","mem","mth","str"}{"",".h"} "${hdrdir}/zp" -install -vm644 "zp/include/zp/priv/"{arch,chr,flt,impl,int,os,std}".h" "${hdrdir}/zp/priv" -install -vm644 "zp/include/zp/bs.d/"{"isconsteval","syscl","trp","urch"}".ii" "${hdrdir}/zp/bs.d" -install -vm644 "zp/include/zp/mem.d/"{"cpy","equ","fil","memcpy","memequ","memfil","memsrh","srh"}".ii" "${hdrdir}/zp/mem.d" -install -vm644 "zp/include/zp/mth.d/"{"abs","dist","divmod","dot","exp","isnan","vadd","vsub"}".ii" "${hdrdir}/zp/mth.d" -install -vm644 "zp/include/zp/mth.d/pair/cpair.ii" "${hdrdir}/zp/mth.d/pair" -install -vm644 "zp/include/zp/mth.d/vec2/cvec.ii" "${hdrdir}/zp/mth.d/vec2" -install -vm644 "zp/include/zp/mth.d/vec3/cvec.ii" "${hdrdir}/zp/mth.d/vec3" -install -vm644 "zp/include/zp/mth.d/vec4/cvec.ii" "${hdrdir}/zp/mth.d/vec4" -install -vm644 "zp/include/zp/str.d/"{"fmt","fmtlen","numdig","strcpy","strequ","strlen","strsrh","utf16dec","utf16declen","utf16enc","utf16enclen","utf8dec","utf8declen","utf8enc","utf8enclen","win1252dec","win1252enc"}".ii" "${hdrdir}/zp/str.d" -install -vm755 "${blddir}/zp/libzp.so" "${libdir}" @@ -106,7 +106,7 @@ int main() { ::zp::i04 filbuf; - cmp(::zp::memfil(&filbuf,0xFFu,sizeof (filbuf)),reinterpret_cast<char unsigned *>(&filbuf+0x1u)+0x1u); + cmp(::zp::memfil(&filbuf,0xFFu,sizeof (filbuf)),&filbuf+0x1u); cmp(filbuf,0xFFFFFFFFFFFFFFFFu); }(); @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg height="768" version="1.1" width="768" xmlns="http://www.w3.org/2000/svg"> + <clipPath id="clipPath61"> + <rect height="768" width="381" x="387" /> + </clipPath> + <clipPath id="clipPath62"> + <rect height="768" width="768" /> + <!--<rect height="768" rx="192" width="768" />--> <!-- Comment above line and uncomment this one (before this comment) for a background with rounded corners. --> + </clipPath> + <clipPath id="clipPath253"> + <rect height="768" width="384" x="384" /> + </clipPath> + <!-- Background --> + <rect clip-path="url(#clipPath62)" fill="#444747" height="768" width="768" /> + <!--<circle fill="#00000000" cx="384" cy="384" r="336" stroke="#444747" stroke-width="96" />--> <!-- Comment above line and uncomment this one (before this comment) for a transparent background. --> + <!-- White Middle Circle --> + <circle fill="#F8F8F1" cx="384" cy="384" r="288"/> + <!-- Digit Eight --> + <circle fill="#00000000" cx="384" cy="536" r="184" stroke="#444747" stroke-width="96" /> + <circle fill="#00000000" cx="384" cy="232" r="184" stroke="#444747" stroke-width="96" /> + <circle fill="#00000000" cx="384" cy="536" r="184" stroke="#A9E13D" stroke-width="32" /> + <circle fill="#00000000" cx="384" cy="232" r="184" stroke="#444747" stroke-width="64" /> + <circle fill="#00000000" cx="384" cy="232" r="184" stroke="#A9E13D" stroke-width="32" /> + <circle clip-path="url(#clipPath61)" fill="#00000000" cx="384" cy="536" r="184" stroke="#444747" stroke-width="64" /> + <circle clip-path="url(#clipPath253)" fill="#00000000" cx="384" cy="536" r="184" stroke="#A9E13D" stroke-width="32" /> + <!-- Greater Ring --> + <circle fill="#00000000" cx="384" cy="384" r="336" stroke="#A9E13D" stroke-width="32" /> +</svg> diff --git a/u8c_boxes.svg b/u8c_boxes.svg new file mode 100644 index 0000000..d6bad80 --- /dev/null +++ b/u8c_boxes.svg @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg height="96" version="1.1" width="256" xmlns="http://www.w3.org/2000/svg"> + <!-- Box #0 --> + <rect fill="#444747" height="64" rx="8" ry="8" width="64" x="24" y="24" /> + <rect fill="#E13DA9" height="64" rx="8" ry="8" width="64" x="16" y="16" /> + <rect fill="#F8F8F1" height="32" width="32" x="32" y="24" /> + <circle fill="#F8F8F1" cx="48" cy="56" r="16"/> + <rect fill="#E13DA9" height="36" width="16" x="40" y="20" /> + <circle fill="#E13DA9" cx="48" cy="56" r="8"/> + <!-- Box #1 --> + <rect fill="#444747" height="64" rx="8" ry="8" width="64" x="104" y="24" /> + <rect fill="#A9E13D" height="64" rx="8" ry="8" width="64" x="96" y="16" /> + <circle fill="#F8F8F1" cx="128" cy="56" r="16"/> + <circle fill="#A9E13D" cx="128" cy="56" r="8"/> + <circle fill="#F8F8F1" cx="128" cy="40" r="16"/> + <circle fill="#A9E13D" cx="128" cy="40" r="8"/> + <!-- Box #2 --> + <rect fill="#444747" height="64" rx="8" ry="8" width="64" x="184" y="24" /> + <rect fill="#3DA9E1" height="64" rx="8" ry="8" width="64" x="176" y="16" /> + <circle fill="#F8F8F1" cx="208" cy="48" r="24"/> + <circle fill="#3DA9E1" cx="208" cy="48" r="16"/> + <polygon fill="#3DA9E1" points="208,48 236,20 236,76" /> +</svg> diff --git a/u8c_braille.svg b/u8c_braille.svg new file mode 100644 index 0000000..b885474 --- /dev/null +++ b/u8c_braille.svg @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg height="168" version="1.1" width="216" xmlns="http://www.w3.org/2000/svg"> + <rect fill="#F8F8F1" height="152" rx="8" ry="8" width="200" x="8" y="8" /> + <rect fill="#444747" height="72" rx="4" ry="4" width="192" x="12" y="84" /> + <rect fill="#444747" height="16" rx="4" ry="4" width="16" x="16" y="16" /> + <rect fill="#444747" height="16" rx="4" ry="4" width="16" x="16" y="40" /> + <rect fill="#444747" height="16" rx="4" ry="4" width="16" x="16" y="64" /> + <rect fill="#444747" height="16" rx="4" ry="4" width="16" x="88" y="16" /> + <rect fill="#444747" height="16" rx="4" ry="4" width="16" x="64" y="40" /> + <rect fill="#444747" height="16" rx="4" ry="4" width="16" x="112" y="16" /> + <rect fill="#444747" height="16" rx="4" ry="4" width="16" x="112" y="40" /> + <rect fill="#E13D3D" height="16" rx="4" ry="4" width="16" x="16" y="88" /> + <rect fill="#E13D3D" height="16" rx="4" ry="4" width="16" x="16" y="136" /> + <rect fill="#E1A93D" height="16" rx="4" ry="4" width="16" x="40" y="136" /> + <rect fill="#A9E13D" height="16" rx="4" ry="4" width="16" x="88" y="88" /> + <rect fill="#E1E13D" height="16" rx="4" ry="4" width="16" x="64" y="136" /> + <rect fill="#A9E13D" height="16" rx="4" ry="4" width="16" x="88" y="136" /> + <rect fill="#3DE13D" height="16" rx="4" ry="4" width="16" x="112" y="88" /> + <rect fill="#3DE1A9" height="16" rx="4" ry="4" width="16" x="136" y="88" /> + <rect fill="#3DE13D" height="16" rx="4" ry="4" width="16" x="112" y="112" /> + <rect fill="#3DE1E1" height="16" rx="4" ry="4" width="16" x="160" y="88" /> + <rect fill="#3DA9E1" height="16" rx="4" ry="4" width="16" x="184" y="88" /> +</svg> diff --git a/zp/CMakeLists.txt b/zp/CMakeLists.txt deleted file mode 100644 index 868a456..0000000 --- a/zp/CMakeLists.txt +++ /dev/null @@ -1,150 +0,0 @@ -cmake_minimum_required(VERSION 3.17) - -set(CMAKE_C_STANDARD 99) -set(CMAKE_CXX_STANDARD 14) - -set(ZP_OBJECT_BS_TRP "source/any/bs/trp.c") -set(ZP_OBJECT_BS_SYSCL "source/any/bs/syscl.c") - -set(ZP_OBJECT_MEM_MEMCPY "source/any/mem/memcpy.cc") -set(ZP_OBJECT_MEM_MEMEQU "source/any/mem/memequ.cc") -set(ZP_OBJECT_MEM_MEMFIL "source/any/mem/memfil.cc") -set(ZP_OBJECT_MEM_MEMSRH "source/any/mem/memsrh.cc") - -set(ZP_OBJECT_MTH_ABS "source/any/mth/abs.cc") -set(ZP_OBJECT_MTH_DIVMOD "source/any/mth/divmod.cc") -set(ZP_OBJECT_MTH_DOT "source/any/mth/dot.cc") -set(ZP_OBJECT_MTH_VADD "source/any/mth/vadd.cc") -set(ZP_OBJECT_MTH_VSUB "source/any/mth/vsub.cc") - -set(ZP_OBJECT_STR_FMT "source/any/str/fmt.cc") -set(ZP_OBJECT_STR_FMTLEN "source/any/str/fmtlen.cc") -set(ZP_OBJECT_STR_STRCPY "source/any/str/strcpy.cc") -set(ZP_OBJECT_STR_STREQU "source/any/str/strequ.cc") -set(ZP_OBJECT_STR_STRLEN "source/any/str/strlen.cc") -set(ZP_OBJECT_STR_STRSRH "source/any/str/strsrh.cc") -set(ZP_OBJECT_STR_UTF16DEC "source/any/str/utf16dec.cc") -set(ZP_OBJECT_STR_UTF16DECLEN "source/any/str/utf16declen.cc") -set(ZP_OBJECT_STR_UTF16ENC "source/any/str/utf16enc.cc") -set(ZP_OBJECT_STR_UTF16ENCLEN "source/any/str/utf16enclen.cc") -set(ZP_OBJECT_STR_UTF32CPY "source/any/str/utf32cpy.cc") -set(ZP_OBJECT_STR_UTF32EQU "source/any/str/utf32equ.cc") -set(ZP_OBJECT_STR_UTF32LEN "source/any/str/utf32len.cc") -set(ZP_OBJECT_STR_UTF32SRH "source/any/str/utf32srh.cc") -set(ZP_OBJECT_STR_UTF8DEC "source/any/str/utf8dec.cc") -set(ZP_OBJECT_STR_UTF8DECLEN "source/any/str/utf8declen.cc") -set(ZP_OBJECT_STR_UTF8ENC "source/any/str/utf8enc.cc") -set(ZP_OBJECT_STR_UTF8ENCLEN "source/any/str/utf8enclen.cc") -set(ZP_OBJECT_STR_WIN1252DEC "source/any/str/win1252dec.cc") -set(ZP_OBJECT_STR_WIN1252ENC "source/any/str/win1252enc.cc") -set(ZP_OBJECT_STR_WSTRCPY "source/any/str/wstrcpy.cc") -set(ZP_OBJECT_STR_WSTREQU "source/any/str/wstrequ.cc") -set(ZP_OBJECT_STR_WSTRLEN "source/any/str/wstrlen.cc") -set(ZP_OBJECT_STR_WSTRSRH "source/any/str/wstrsrh.cc") - -if("${ZP_TARGET_}" STREQUAL "Amd64") - set(ZP_OBJECT_BS_SYSCL "source/amd64/bs/syscl.s") - set(ZP_OBJECT_BS_TRP "source/amd64/bs/trp.s") - - set(ZP_OBJECT_MEM_MEMCPY "source/amd64/mem/memcpy.s") - set(ZP_OBJECT_MEM_MEMFIL "source/amd64/mem/memfil.s") -endif() - -if("${ZP_TARGET_}" STREQUAL "Arm") - set(ZP_OBJECT_BS_SYSCL "source/arm/bs/syscl.s") - set(ZP_OBJECT_MEM_MEMCPY "source/arm/mem/memcpy.s") -endif() - -if("${ZP_TARGET_}" STREQUAL "Arm64") - set(ZP_OBJECT_BS_SYSCL "source/arm64/bs/syscl.s") - set(ZP_OBJECT_MEM_MEMCPY "source/arm64/mem/memcpy.s") -endif() - -if("${ZP_TARGET_}" STREQUAL "Ia32") - set(ZP_OBJECT_BS_SYSCL "source/ia32/bs/syscl.s") -endif() - -if(NOT ${ZP_ENABLE_SYSTEM_CALLS}) - set(ZP_OBJECT_BS_SYSCL "") -endif() - -add_library( - zp ${ZP_LIBRARY_TYPE_VALUE} - - "${ZP_OBJECT_BS_TRP}" - "${ZP_OBJECT_BS_SYSCL}" - - "${ZP_OBJECT_MEM_MEMCPY}" - "${ZP_OBJECT_MEM_MEMEQU}" - "${ZP_OBJECT_MEM_MEMFIL}" - "${ZP_OBJECT_MEM_MEMSRH}" - - "${ZP_OBJECT_MTH_ABS}" - "${ZP_OBJECT_MTH_DIVMOD}" - "${ZP_OBJECT_MTH_DOT}" - "${ZP_OBJECT_MTH_VADD}" - "${ZP_OBJECT_MTH_VSUB}" - - "${ZP_OBJECT_STR_FMT}" - "${ZP_OBJECT_STR_FMTLEN}" - "${ZP_OBJECT_STR_STRCPY}" - "${ZP_OBJECT_STR_STREQU}" - "${ZP_OBJECT_STR_STRLEN}" - "${ZP_OBJECT_STR_STRSRH}" - "${ZP_OBJECT_STR_UTF16DEC}" - "${ZP_OBJECT_STR_UTF16DECLEN}" - "${ZP_OBJECT_STR_UTF16ENC}" - "${ZP_OBJECT_STR_UTF16ENCLEN}" - "${ZP_OBJECT_STR_UTF32CPY}" - "${ZP_OBJECT_STR_UTF32EQU}" - "${ZP_OBJECT_STR_UTF32LEN}" - "${ZP_OBJECT_STR_UTF32SRH}" - "${ZP_OBJECT_STR_UTF8DEC}" - "${ZP_OBJECT_STR_UTF8DECLEN}" - "${ZP_OBJECT_STR_UTF8ENC}" - "${ZP_OBJECT_STR_UTF8ENCLEN}" - "${ZP_OBJECT_STR_WIN1252DEC}" - "${ZP_OBJECT_STR_WIN1252ENC}" - "${ZP_OBJECT_STR_WSTRCPY}" - "${ZP_OBJECT_STR_WSTREQU}" - "${ZP_OBJECT_STR_WSTRLEN}" - "${ZP_OBJECT_STR_WSTRSRH}" -) - -target_include_directories( - zp PUBLIC - - "include" -) - -target_compile_definitions( - zp PRIVATE - - zp_priv_nconsteval -) - -if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang|GNU") - target_compile_options( - zp PRIVATE - - $<IF:$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">,-Og,-Oz> - -Wall - -Wextra - -Wmissing-prototypes - -Wpedantic - -fdiagnostics-color=always - -ffreestanding - -fno-exceptions - -fshort-enums - $<IF:$<STREQUAL:"${ZP_LIBRARY_TYPE}","Shared">,-g,> - -nostdlib - ) -elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - target_compile_options( - zp PRIVATE - - /O2 - /W4 - $<IF:$<STREQUAL:"${ZP_LIBRARY_TYPE}","Shared">,$<IF:$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">,/Zo>> - ) -endif() diff --git a/zp/GNUmakefile b/zp/GNUmakefile new file mode 100644 index 0000000..291729c --- /dev/null +++ b/zp/GNUmakefile @@ -0,0 +1,267 @@ +# Copyright 2022-2023 Gabriel Jensen. +# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. + +ifeq "$(targ)" "" +targ := $(shell ../getTarget.sh) +ifeq "$(targ)" "unknown" +$(error Unable to detect target!) +endif +$(info Detected target $(targ)!) +endif + +ifeq "$(targ)" "amd64" +AS := nasm -felf64 +endif + +ifeq "$(stdc)" "" +stdc := c99 +endif + +ifeq "$(stdcxx)" "" +stdcxx := c++14 +endif + +OBJ_BS_TRP := source/any/bs/trp.o + +OBJ_MEM_MEMCPY := source/any/mem/memcpy.o +OBJ_MEM_MEMEQU := source/any/mem/memequ.o +OBJ_MEM_MEMFIL := source/any/mem/memfil.o +OBJ_MEM_MEMSRH := source/any/mem/memsrh.o + +OBJ_MTH_ABS := source/any/mth/abs.o +OBJ_MTH_DIVMOD := source/any/mth/divmod.o +OBJ_MTH_DOT := source/any/mth/dot.o +OBJ_MTH_VADD := source/any/mth/vadd.o +OBJ_MTH_VSUB := source/any/mth/vsub.o + +OBJ_STR_FMT := source/any/str/fmt.o +OBJ_STR_FMTLEN := source/any/str/fmtlen.o +OBJ_STR_STRCPY := source/any/str/strcpy.o +OBJ_STR_STREQU := source/any/str/strequ.o +OBJ_STR_STRLEN := source/any/str/strlen.o +OBJ_STR_STRSRH := source/any/str/strsrh.o +OBJ_STR_UTF16DEC := source/any/str/utf16dec.o +OBJ_STR_UTF16DECLEN := source/any/str/utf16declen.o +OBJ_STR_UTF16ENC := source/any/str/utf16enc.o +OBJ_STR_UTF16ENCLEN := source/any/str/utf16enclen.o +OBJ_STR_UTF32CPY := source/any/str/utf32cpy.o +OBJ_STR_UTF32EQU := source/any/str/utf32equ.o +OBJ_STR_UTF32LEN := source/any/str/utf32len.o +OBJ_STR_UTF32SRH := source/any/str/utf32srh.o +OBJ_STR_UTF8DEC := source/any/str/utf8dec.o +OBJ_STR_UTF8DECLEN := source/any/str/utf8declen.o +OBJ_STR_UTF8ENC := source/any/str/utf8enc.o +OBJ_STR_UTF8ENCLEN := source/any/str/utf8enclen.o +OBJ_STR_WIN1252DEC := source/any/str/win1252dec.o +OBJ_STR_WIN1252ENC := source/any/str/win1252enc.o +OBJ_STR_WSTRCPY := source/any/str/wstrcpy.o +OBJ_STR_WSTREQU := source/any/str/wstrequ.o +OBJ_STR_WSTRLEN := source/any/str/wstrlen.o +OBJ_STR_WSTRSRH := source/any/str/wstrsrh.o + +OBJ_BS_SYSCL := source/any/bs/syscl.o + +ifeq "$(targ)" "amd64" + +OBJ_BS_SYSCL := source/amd64/bs/syscl.o +OBJ_BS_TRP := source/amd64/bs/trp.o + +OBJ_MEM_MEMCPY := source/amd64/mem/memcpy.o +OBJ_MEM_MEMFIL := source/amd64/mem/memfil.o + +else ifeq "$(targ)" "arm" + +OBJ_BS_SYSCL := source/arm/bs/syscl.o + +else ifeq "$(targ)" "arm64" + +OBJ_BS_SYSCL := source/arm64/bs/syscl.o + +else ifeq "$(targ)" "ia32" + +OBJ_BS_SYSCL := source/ia32/bs/syscl.o + +endif + +OBJS := \ + $(OBJ_BS_TRP) \ + \ + $(OBJ_MEM_MEMCPY) \ + $(OBJ_MEM_MEMEQU) \ + $(OBJ_MEM_MEMFIL) \ + $(OBJ_MEM_MEMSRH) \ + \ + $(OBJ_MTH_ABS) \ + $(OBJ_MTH_DIVMOD) \ + $(OBJ_MTH_DOT) \ + $(OBJ_MTH_VADD) \ + $(OBJ_MTH_VSUB) \ + \ + $(OBJ_STR_FMT) \ + $(OBJ_STR_FMTLEN) \ + $(OBJ_STR_STRCPY) \ + $(OBJ_STR_STREQU) \ + $(OBJ_STR_STRLEN) \ + $(OBJ_STR_STRSRH) \ + $(OBJ_STR_UTF16DEC) \ + $(OBJ_STR_UTF16DECLEN) \ + $(OBJ_STR_UTF16ENC) \ + $(OBJ_STR_UTF16ENCLEN) \ + $(OBJ_STR_UTF32CPY) \ + $(OBJ_STR_UTF32EQU) \ + $(OBJ_STR_UTF32LEN) \ + $(OBJ_STR_UTF32SRH) \ + $(OBJ_STR_UTF8DEC) \ + $(OBJ_STR_UTF8DECLEN) \ + $(OBJ_STR_UTF8ENC) \ + $(OBJ_STR_UTF8ENCLEN) \ + $(OBJ_STR_WIN1252DEC) \ + $(OBJ_STR_WIN1252ENC) \ + $(OBJ_STR_WSTRCPY) \ + $(OBJ_STR_WSTREQU) \ + $(OBJ_STR_WSTRLEN) \ + $(OBJ_STR_WSTRSRH) + +ifneq "$(nosyscl)" "true" +OBJS := \ + $(OBJS) \ + $(OBJ_BS_SYSCL) +endif + +ifeq "$(shrlib)" "true" +LIB := libzp.so +else +LIB := libzp.a +endif + +HDRS := \ + include/zp/bs \ + include/zp/bs.h \ + include/zp/mem \ + include/zp/mem.h \ + include/zp/mth \ + include/zp/mth.h \ + include/zp/str \ + include/zp/str.h \ + include/zp/bs.d/isconsteval.ii \ + include/zp/bs.d/syscl.ii \ + include/zp/bs.d/trp.ii \ + include/zp/bs.d/urch.ii \ + include/zp/mem.d/cpy.ii \ + include/zp/mem.d/equ.ii \ + include/zp/mem.d/fil.ii \ + include/zp/mem.d/memcpy.ii \ + include/zp/mem.d/memequ.ii \ + include/zp/mem.d/memfil.ii \ + include/zp/mem.d/memsrh.ii \ + include/zp/mem.d/srh.ii \ + include/zp/mth.d/abs.ii \ + include/zp/mth.d/dist.ii \ + include/zp/mth.d/divmod.ii \ + include/zp/mth.d/dot.ii \ + include/zp/mth.d/exp.ii \ + include/zp/mth.d/isnan.ii \ + include/zp/mth.d/vadd.ii \ + include/zp/mth.d/vsub.ii \ + include/zp/mth.d/pair/cpair.ii \ + include/zp/mth.d/vec2/cvec.ii \ + include/zp/mth.d/vec3/cvec.ii \ + include/zp/mth.d/vec4/cvec.ii \ + include/zp/priv/arc.h \ + include/zp/priv/chr.h \ + include/zp/priv/flt.h \ + include/zp/priv/imp.h \ + include/zp/priv/int.h \ + include/zp/priv/std.h \ + include/zp/priv/sys.h \ + include/zp/str.d/fmt.ii \ + include/zp/str.d/fmtlen.ii \ + include/zp/str.d/numdig.ii \ + include/zp/str.d/strcpy.ii \ + include/zp/str.d/strequ.ii \ + include/zp/str.d/strlen.ii \ + include/zp/str.d/strsrh.ii \ + include/zp/str.d/utf16dec.ii \ + include/zp/str.d/utf16declen.ii \ + include/zp/str.d/utf16enc.ii \ + include/zp/str.d/utf16enclen.ii \ + include/zp/str.d/utf8dec.ii \ + include/zp/str.d/utf8declen.ii \ + include/zp/str.d/utf8enc.ii \ + include/zp/str.d/utf8enclen.ii \ + include/zp/str.d/win1252dec.ii \ + include/zp/str.d/win1252enc.ii \ + +CFLAGS := \ + -Iinclude \ + -Oz \ + -Wall \ + -Wextra \ + -ffreestanding \ + -fshort-enums \ + -nostdlib \ + -pipe \ + -std=$(stdc) + +CXXFLAGS := \ + -Dzp_priv_nconsteval \ + -Iinclude \ + -Oz \ + -Wall \ + -Wextra \ + -ffreestanding \ + -fno-exceptions \ + -fshort-enums \ + -nostdlib \ + -pipe \ + -std=$(stdcxx) + +ifeq "$(shrlib)" "true" +CFLAGS := \ + $(CFLAGS) \ + -g + +CXXFLAGS := \ + $(CXXFLAGS) \ + -g + +LDFLAGS := \ + $(LDFLAGS) \ + -shared +endif + +.PHONY: clean install purge + +ifeq "$(shrlib)" "true" +$(LIB): $(OBJS) + $(CC) $(LDFLAGS) -o$(@) $(^) +else +$(LIB): $(OBJS) + $(AR) r $(@) $(^) +endif + +$(OBJS): $(HDRS) + +install: $(LIB) + mkdir -pvm755 "$(HDRDIR)/zp/priv" + mkdir -pvm755 "$(HDRDIR)/zp/"("bs","mem","str")".d" + mkdir -pvm755 "$(HDRDIR)/zp/mth.d/"("pair","vec2","vec3","vec4") + mkdir -pvm755 "$(LIBDIR)" + install -vm644 "zp/include/zp/"("bs","mem","mth","str")("",".h") "$(HDRDIR)/zp" + install -vm644 "zp/include/zp/priv/"("arc","chr","flt","imp","int","std","sys")".h" "$(HDRDIR)/zp/priv" + install -vm644 "zp/include/zp/bs.d/"("isconsteval","syscl","trp","urch")".ii" "$(HDRDIR)/zp/bs.d" + install -vm644 "zp/include/zp/mem.d/"("cpy","equ","fil","memcpy","memequ","memfil","memsrh","srh")".ii" "$(HDRDIR)/zp/mem.d" + install -vm644 "zp/include/zp/mth.d/"("abs","dist","divmod","dot","exp","isnan","vadd","vsub")".ii" "$(HDRDIR)/zp/mth.d" + install -vm644 "zp/include/zp/mth.d/pair/cpair.ii" "$(HDRDIR)/zp/mth.d/pair" + install -vm644 "zp/include/zp/mth.d/vec2/cvec.ii" "$(HDRDIR)/zp/mth.d/vec2" + install -vm644 "zp/include/zp/mth.d/vec3/cvec.ii" "$(HDRDIR)/zp/mth.d/vec3" + install -vm644 "zp/include/zp/mth.d/vec4/cvec.ii" "$(HDRDIR)/zp/mth.d/vec4" + install -vm644 "zp/include/zp/str.d/"("fmt","fmtlen","numdig","strcpy","strequ","strlen","strsrh","utf16dec","utf16declen","utf16enc","utf16enclen","utf8dec","utf8declen","utf8enc","utf8enclen","win1252dec","win1252enc")".ii" "$(HDRDIR)/zp/str.d" + install -vm755 "$(LIB)" "$(LIBDIR)" + +clean: + $(RM) $(OBJS) + +purge: clean + $(RM) $(LIB) diff --git a/zp/source/amd64/bs/syscl.s b/zp/source/amd64/bs/syscl.s index 1161625..af0bf1a 100644 --- a/zp/source/amd64/bs/syscl.s +++ b/zp/source/amd64/bs/syscl.s @@ -1,27 +1,27 @@ -# Copyright 2022-2023 Gabriel Jensen. -# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. +; Copyright 2022-2023 Gabriel Jensen. +; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +; If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. -.globl zp_syscl +global zp_syscl zp_syscl: - # System calls on AMD64 use the following registers: - # rax : System call identifier - # rdi : First parameter - # rsi : Second parameter - # rdx : Third parameter - # r10 : Fourth parameter - # r8 : Fifth parameter - # r9 : Sixth parameter - # eax : Return value - # No registers to save. - movq %rdi,%rax # Move the first parameter (the identifier) to rax. - movq %rsi,%rdi # Move parameters into their designated registers. - movq %rdx,%rsi - movq %rcx,%rdx - movq %r8,%r10 # System calls use r10 instead of rcx. - movq %r9,%r8 - movq 0x8(%rsp),%r9 # Extract the sixth argument from the stack. - syscall # Slime incident - # No need to move the return value. + ; System calls on AMD64 use the following registers: + ; rax : System call identifier + ; rdi : First parameter + ; rsi : Second parameter + ; rdx : Third parameter + ; r10 : Fourth parameter + ; r8 : Fifth parameter + ; r9 : Sixth parameter + ; eax : Return value + ; No registers to save. + mov rax,rdi ; Move the first parameter (the identifier) to rax. + mov rdi,rsi ; Move parameters into their designated registers. + mov rsi,rdx + mov rdx,rcx + mov r10,r8 ; System calls use r10 instead of rcx. + mov r8,r9 + mov r9,[rsp + 0x8] ; Extract the sixth argument from the stack. + syscall ; Slime incident + ; No need to move the return value. ret diff --git a/zp/source/amd64/bs/trp.s b/zp/source/amd64/bs/trp.s index 614aba0..91efa4e 100644 --- a/zp/source/amd64/bs/trp.s +++ b/zp/source/amd64/bs/trp.s @@ -1,10 +1,8 @@ -# Copyright 2022-2023 Gabriel Jensen. -# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. +; Copyright 2022-2023 Gabriel Jensen. +; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +; If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. -.intel_syntax noprefix - -.globl zp_trp +global zp_trp zp_trp: ud2 diff --git a/zp/source/amd64/mem/memcpy.s b/zp/source/amd64/mem/memcpy.s index 99344e7..69a9226 100644 --- a/zp/source/amd64/mem/memcpy.s +++ b/zp/source/amd64/mem/memcpy.s @@ -1,66 +1,64 @@ -# Copyright 2022-2023 Gabriel Jensen. -# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. +; Copyright 2022-2023 Gabriel Jensen. +; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +; If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. -.intel_syntax noprefix - -.globl zp_memcpy +global zp_memcpy zp_memcpy: - # zp_i8 val1; - # zp_i04 vali8; - # int unsigned128_t vali01; - # int unsigned256_t vali02; + ; zp_i8 val1; + ; zp_i04 vali8; + ; int unsigned128_t vali01; + ; int unsigned256_t vali02; -.big02cpy: # big02cpy:; // We assume AVX. +.big02cpy: ; big02cpy:; // We assume AVX. cmp rdx,0x20 - jl short .big01cpy # if (rem < 0x20u) goto big01cpy; + jl short .big01cpy ; if (rem < 0x20u) goto big01cpy; - vmovdqu ymm0,[rsi] # vali02 = *(int unsigned256_t *)src; - vmovdqu [rdi],ymm0 # *(int unsigned256_t *)dst = vali02; + vmovdqu ymm0,[rsi] ; vali02 = *(int unsigned256_t *)src; + vmovdqu [rdi],ymm0 ; *(int unsigned256_t *)dst = vali02; - add rdi,0x20 # dst += 0x20u; - add rsi,0x20 # src += 0x20u; - sub rdx,0x20 # rem -= 0x20u; - jmp short .big02cpy # goto big02cpy; + add rdi,0x20 ; dst += 0x20u; + add rsi,0x20 ; src += 0x20u; + sub rdx,0x20 ; rem -= 0x20u; + jmp short .big02cpy ; goto big02cpy; -.big01cpy: # big01cpy:; +.big01cpy: ; big01cpy:; cmp rdx,0x10 - jl short .wrdcpy # if (rem < 0x10u) goto wrdcpy; + jl short .wrdcpy ; if (rem < 0x10u) goto wrdcpy; - movdqu xmm0,[rsi] # vali01 = *(int unsigned128_t *)src; - movdqu [rdi],xmm0 # *(int unsigned128_t *)dst = vali01; + movdqu xmm0,[rsi] ; vali01 = *(int unsigned128_t *)src; + movdqu [rdi],xmm0 ; *(int unsigned128_t *)dst = vali01; - add rdi,0x10 # dst += 0x10u; - add rsi,0x10 # src += 0x10u; - sub rdx,0x10 # rem -= 0x10u; - jmp short .big01cpy # goto big01cpy; + add rdi,0x10 ; dst += 0x10u; + add rsi,0x10 ; src += 0x10u; + sub rdx,0x10 ; rem -= 0x10u; + jmp short .big01cpy ; goto big01cpy; -.wrdcpy: # wrdcpy:; +.wrdcpy: ; wrdcpy:; cmp rdx,0x8 - jl short .bytcpy # if (rem < 0x8u) goto bytcpy; + jl short .bytcpy ; if (rem < 0x8u) goto bytcpy; - mov rcx,[rsi] # vali8 = *(zp_i04 *)src; - mov [rdi],rcx # *(zp_i04 *)dst = vali8; + mov rcx,[rsi] ; vali8 = *(zp_i04 *)src; + mov [rdi],rcx ; *(zp_i04 *)dst = vali8; - add rsi,0x8 # dst += 0x8u; - add rdi,0x8 # src += 0x8u; - sub rdx,0x8 # rem -= 0x8u; - jmp short .wrdcpy # goto wrdcpy + add rsi,0x8 ; dst += 0x8u; + add rdi,0x8 ; src += 0x8u; + sub rdx,0x8 ; rem -= 0x8u; + jmp short .wrdcpy ; goto wrdcpy -.bytcpy: # bytcpy:; - test rdx,rdx # if (rem == 0x0) - jz short .done # goto done +.bytcpy: ; bytcpy:; + test rdx,rdx ; if (rem == 0x0) + jz short .done ; goto done - mov cl,[rsi] # val1 = *(zp_i8 *)src; - mov [rdi],cl # *(zp_i8 *)dst = val1; + mov cl,[rsi] ; val1 = *(zp_i8 *)src; + mov [rdi],cl ; *(zp_i8 *)dst = val1; - inc rdi # ++dst; - inc rsi # ++src; - dec rdx # --rem; - jmp short .bytcpy # goto bytcpy; + inc rdi ; ++dst; + inc rsi ; ++src; + dec rdx ; --rem; + jmp short .bytcpy ; goto bytcpy; .done: mov rax,rdi mov rdx,rsi - ret # return (zp_cpyres) {.dst = dst,.src = src}; + ret ; return (zp_cpyres) {.dst = dst,.src = src}; diff --git a/zp/source/amd64/mem/memfil.s b/zp/source/amd64/mem/memfil.s index 8ce45fc..7089d63 100644 --- a/zp/source/amd64/mem/memfil.s +++ b/zp/source/amd64/mem/memfil.s @@ -1,36 +1,34 @@ -# Copyright 2022-2023 Gabriel Jensen. -# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. +; Copyright 2022-2023 Gabriel Jensen. +; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +; If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. -.intel_syntax noprefix - -.globl zp_memfil +global zp_memfil zp_memfil: - movzx rsi,sil # zp_i04 extval = val; - mov rax,0x0101010101010101 # zp_i04 val = 0x0101010101010101u; - imul rax,rsi # val *= extval; + movzx rsi,sil ; zp_i04 extval = val; + mov rax,0x0101010101010101 ; zp_i04 val = 0x0101010101010101u; + imul rax,rsi ; val *= extval; -.wrdfil: # wrdfil:; +.wrdfil: ; wrdfil:; cmp rdx,0x8 - jl short .bytfil # if (num < 0x8u) goto bytfil; + jl short .bytfil ; if (num < 0x8u) goto bytfil; - mov [rdi],rax # *(zp_i04 *)dst = vali8; + mov [rdi],rax ; *(zp_i04 *)dst = vali8; - add rdi,0x8 # dst += 0x8u; - sub rdx,0x8 # num -= 0x8u; - jmp short .wrdfil # goto wrdfil + add rdi,0x8 ; dst += 0x8u; + sub rdx,0x8 ; num -= 0x8u; + jmp short .wrdfil ; goto wrdfil -.bytfil: # bytfil:; - test rdx,rdx # if (rem == 0x0) - jz short .done # goto done +.bytfil: ; bytfil:; + test rdx,rdx ; if (rem == 0x0) + jz short .done ; goto done - mov [rdi],al # *(zp_i8 *)dst = val1; + mov [rdi],al ; *(zp_i8 *)dst = val1; - inc rdi # ++dst; - dec rdx # --rem; - jmp short .bytfil # goto bytfil; + inc rdi ; ++dst; + dec rdx ; --rem; + jmp short .bytfil ; goto bytfil; .done: mov rax,rdi - ret # return dst; + ret ; return dst; diff --git a/zp/source/any/bs/syscl.c b/zp/source/any/bs/syscl.cc index 33423cf..18c9ae1 100644 --- a/zp/source/any/bs/syscl.c +++ b/zp/source/any/bs/syscl.cc @@ -4,8 +4,8 @@ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. */ -#include <zp/bs.h> +#include <zp/bs> -zp_sysclres zp_syscl(zp_nuse zp_sysclid id,...) { - zp_urch(); // Unsupported. +extern "C" ::zp::sysclres zp_syscl(zp_nuse ::zp::sysclid id,...) { + ::zp::urch(); // Unsupported. } diff --git a/zp/source/any/bs/trp.c b/zp/source/any/bs/trp.cc index 3b9bbc7..9985588 100644 --- a/zp/source/any/bs/trp.c +++ b/zp/source/any/bs/trp.cc @@ -4,9 +4,9 @@ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. */ -#include <zp/bs.h> +#include <zp/bs> -void zp_trp(void) { +extern "C" void zp_trp() { #if zp_priv_hasbuiltin(__builtin_trap) __builtin_trap(); #endif |