Author Topic: BASELIB: General Purpose Lib for Beginners  (Read 74650 times)

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #30 on: March 27, 2017, 02:13:48 PM »
BASELIB Revision 1.1.16

core.zip (source)
binary.zip (binaries)

What's New (May 8, 2017)

[1] Fixed stack corruptions in "prndbl" and "dbl2str" in all SBASE3 variants.


You can visit my profile for similar downloads and other things here

or you can directly download them from my drive
« Last Edit: May 08, 2017, 10:04:23 AM by stressful »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #31 on: June 02, 2017, 05:18:52 PM »
BASELIB Revision 2.0

core.zip (source)
binary.zip (binaries)

What's New (July 16, 2017) Revision 2.0
[1] Added "memview2"
[2] Added "mem_insert"
[3] Added "byte_count"

For latest downloads:

You can visit my profile for similar downloads and other things here

or you can directly download them from my drive

You can safely ignore other attachments found previously in this thread.
« Last Edit: July 27, 2017, 10:30:51 PM by stressful »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #32 on: August 19, 2017, 04:38:43 PM »
BASELIB Revision 2.4 (September 28th, 2017)

Attached: core.zip (source), binary.zip (binaries), corelib.zip(source and binaries).

What's New
[1] Fixed a fatal bug in prnflt, prnfltr, flt2str that causes dumpmmx, dumpxmm and dumpymm to freeze on divide-by-zero exception operating on REAL4 floats data. All sources and binaries are affected by this fix.

For latest downloads:

- You can visit my profile for similar downloads and other things here

- or you can directly download them from my drive

or from sourceforge

Please ignore other attachments of similar libraries found in the previous posts.
« Last Edit: October 15, 2017, 11:18:45 AM by stressful »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #33 on: October 02, 2017, 02:07:58 AM »
If you have AVX CPU and want to start learning AVX programming, then BASELIB offers various utilites to do just that via prnymm, dumpymm, clearymm and sse_flags routines. They are accessible in both binaries mode and source mode supplied in the attachment (Revision 2.4) in the above post.

Sample demo code (via binaries BASE3.DLL on 32-bit Windows with AVX support, using GCC as the linker)
Code: [Select]
;--------------------
;nasm -f win this.asm
;gcc -m32 this.obj base3.dll -s -o this.exe
;--------------------
global _WinMain@16

extern _clearymm
extern _dumpymm
extern _prnline

section .data align=32
w dq 10.23,11.43,12.54,17.95
x dq 89.54,98.14,55.16,19.11
y dq 45.12,65.22,14.17,29.16
z dq 56.33,51.01,54.86,28.54
a dq 00.00,05.00,00.00,00.00

section .text
_WinMain@16:
        push    ebp             ;C's standard prologue
        mov     ebp,esp
        call    _clearymm       ;YMMs are dirty
        vmovapd ymm4,[w]        ;data population
        vmovapd ymm5,[x]
        vmovapd ymm6,[y]
        vmovapd ymm7,[z]
        vmovapd ymm0,[a]
        mov     eax,1           ;option to view as packed quads
        call    _dumpymm        ;See initial population
        call    _prnline
        vdivpd  ymm1,ymm4,ymm0  ;perform an AVX packed division. YMM1 = YMM4 / YMM0
        mov     eax,1           ;See the result after division
        call    _dumpymm
        pop     ebp             ;Epilogue
        ret

The code above produces the following output
Code: [Select]
YMM0: 0.0|0.0|5.0|0.0   ;the YMM registers after data population
YMM1: 0.0|0.0|0.0|0.0
YMM2: 0.0|0.0|0.0|0.0
YMM3: 0.0|0.0|0.0|0.0
YMM4: 17.95|12.54|11.43|10.23
YMM5: 19.11|55.16|98.14|89.54
YMM6: 29.16|14.17|65.22|45.12
YMM7: 28.54|54.86|51.01|56.33

YMM0: 0.0|0.0|5.0|0.0   ;the YMM registers after packed divisions on four REAL8 data
YMM1: #|#|2.286|#
YMM2: 0.0|0.0|0.0|0.0
YMM3: 0.0|0.0|0.0|0.0
YMM4: 17.95|12.54|11.43|10.23
YMM5: 19.11|55.16|98.14|89.54
YMM6: 29.16|14.17|65.22|45.12
YMM7: 28.54|54.86|51.01|56.33

EDIT: Added the equivalent code for Linux32. Using BASE3.O and GCC as linker. Your CPU must have AVX support.
Code: [Select]
;--------------------
; nasm -f elf this.asm
; gcc -m32 this.o base3.o -s -o this
; ./this
;--------------------
global main

extern clearymm
extern dumpymm
extern prnline

section .data align=32
w dq 10.23,11.43,12.54,17.95
x dq 89.54,98.14,55.16,19.11
y dq 45.12,65.22,14.17,29.16
z dq 56.33,51.01,54.86,28.54
a dq 00.00,05.00,00.00,00.00

section .text
main:
push ebp ;C's standard prologue
mov ebp,esp
call clearymm ;YMMs are dirty
vmovapd ymm4,[w] ;data population
vmovapd ymm5,[x]
vmovapd ymm6,[y]
vmovapd ymm7,[z]
vmovapd ymm0,[a]
mov eax,1 ;option to view as packed quads
call dumpymm ;See initial population
call prnline
vdivpd ymm1,ymm4,ymm0 ;perform an AVX packed division
mov eax,1 ;See the result after division
call dumpymm
pop ebp ;Epilogue
ret
« Last Edit: October 02, 2017, 03:31:54 AM by stressful »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #34 on: October 05, 2017, 02:55:28 AM »
This example below demonstrates how one safely probe the system's kernel on Linux for any valuable information returned. Example, in accessing MMAP and MUNMAP, with dumpreg as the helper to verify values returned in RAX. dumpreg routine is accesible from base6.o

Code: [Select]
;-------------------------
;nasm -f elf64 this.asm
;ld this.o base6.o -o this (base6.o is from BASELIB)
;./this
;-------------------------
global _start

extern dumpreg ;from base6.o

section .text
_start:
mov r9,0 ;unsigned long off
mov r8,-1 ;unsigned long fd
mov r10,0x21 ;unsigned long flags
mov rdx,0x3 ;unsigned long prot
mov rsi,0x1000 ;unsigned long size
mov rdi,0 ;unsigned long addr
mov rax,9 ;mmap()
syscall
call dumpreg ;confirm return value in RAX (This is your new allocated area)

dealloc:
mov rsi,0x1000
mov rdi,rax
mov rax,11 ;munmap()
syscall
call dumpreg ;success RAX = 0

exit: xor edi,edi
mov eax,60
syscall

;Equates (from <sys/mmap.h>)
;MAP_SHARED equ 0x1
;MAP_ANONYMOUS  equ 0x20
;PROT_READ  equ 0x1
;PROT_WRITE equ 0x2

Once you are satisfied with all the information returned, then you can delete / disable the calls to base6.o (dumpreg). Output from the 2 dumpregs used above:

Code: [Select]
RAX|00007FE9C14D5000 RBX|0000000000000000 RCX|00000000004000D9  ;RAX points to new area allocated by MMAP.
RDX|0000000000000003 RSI|0000000000001000 RDI|0000000000000000
R8 |FFFFFFFFFFFFFFFF R9 |0000000000000000 R10|0000000000000021
R11|0000000000000202 R12|0000000000000000 R13|0000000000000000
R14|0000000000000000 R15|0000000000000000 RBP|0000000000000000
RSP|00007FFFF4343390 RIP|00000000004000D9 [UHex]

RAX|0000000000000000 RBX|0000000000000000 RCX|00000000004000ED  ;RAX indicates MUNMAP is successful. Memory allocated is returned.
RDX|0000000000000003 RSI|0000000000001000 RDI|00007FE9C14D5000
R8 |FFFFFFFFFFFFFFFF R9 |0000000000000000 R10|0000000000000021
R11|0000000000000206 R12|0000000000000000 R13|0000000000000000
R14|0000000000000000 R15|0000000000000000 RBP|0000000000000000
RSP|00007FFFF4343390 RIP|00000000004000ED [UHex]

You can further verify the newly allocated area using other advanced routines from BASELIB such as memview and memview2 by importing them via externs.

You can download BASELIB from the post above (revision 2.4) or from sourceforge

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #35 on: October 05, 2017, 03:11:04 AM »
REVISION 2.7
Nov 19th, 2017

[1]Minor fixes to "sort_byte". Now sort signed bytes only
[2]Minor fixes to "sort_int" stack versions - One volatile register not saved
[3]"memview2" is switched with "memview" (64-bit)
[4]"memview2" is dropped - replaced by "memview" (32-bit)
[5]Minor fixes to mem_alloc/mem_free(Win64)

Introducing "cpulib.zip" - A partially ABI-compliant version of BASELIB. Callable from C. This is not compatible with BASELIB. For Win and Linux.

Download BASELIB. Or download directly below (revision 2.7)
« Last Edit: November 22, 2017, 04:06:38 AM by stressful »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #36 on: December 25, 2017, 12:45:06 PM »
(23.Feb.2018) Revision 3.3
[1] Fixed fatal bug in "flags" due to careless previous modifications. All 32-bit stack versions

What to download (you need to log-in to be able to see the attachments below). The attachments are now NASM-only.
[1] baselib.zip (BASELIB sources and binaries). Linux. Win. 32-bit and 64-bit
[2] cpulib.zip (CPULIB source and binaries). Not compatible with BASELIB. Linux. Win. 32-bit and 64-bit

All three of the above are standalone.

Note that this is NASM-only attachments. For other syntax of BASELIB you can download the full size of BASELIB/CPULIB from Sourceforge or from my Google+ profile.

You should ignore older attachments found in this thread or in other thread.
« Last Edit: February 22, 2018, 04:11:02 PM by stressful »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #37 on: March 03, 2018, 08:19:29 PM »
(25.March.2018) Revision 3.3.1

What to download:
[1] baselibs.zip (BASELIB sources and binaries). Linux. Win. 32-bit and 64-bit
[2] cpulib.zip (CPULIB source and binaries). Not compatible with BASELIB. Linux. Win. 32-bit and 64-bit

Each one of the above are standalone.

Download from:
1. BASELIBS project at ,sourceforge
2. my Google drive or
3. my Google+ profile.

You should ignore older attachments found in this thread or in other thread..
« Last Edit: April 09, 2018, 02:12:00 PM by stressful »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #38 on: June 17, 2018, 08:10:22 AM »
(9.Aug.2018) Revision 3.5
This is release with major structural changes
[1] Bug fixes to "timer_start". All Win64 versions
[2] Use only GCC for sources and binaries linking.

What to download:
[1] baselibs.zip (BASELIB sources and binaries). Linux. Win. 32-bit and 64-bit
[2] cpulib.zip (CPULIB source and binaries). Not compatible with BASELIB. Linux. Win. 32-bit and 64-bit

Each one of the above are standalone. You should ignore older attachments found in this thread or in other thread. Download from attachment below or from either one of these sites (plus other syntaxes);

1) Sourceforge's baselibs 
2) Google Drive's BASEUPLOADS
« Last Edit: August 09, 2018, 10:12:06 AM by stressful »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #39 on: August 19, 2018, 05:16:49 PM »
(13.Oct.2018) Revision 4.0.3
[1] Minor improvement / fixes here and there. Nothing big.

What to download:
[1] baselibs.zip (BASELIB sources and binaries). Linux. Win. 32-bit and 64-bit
[2] cpulib.zip (CPULIB source and binaries). Not compatible with BASELIB. Linux. Win. 32-bit and 64-bit
[3] fullbinaries.zip. For other binaries not included in [1] and [2] such as .DLL and .SO. Using linkers other than GCC (LINK, ld, Golink).

Each one of the above are standalone. You should ignore older attachments found in this thread or in other thread. Download from attachment below or from either one of these sites (plus other syntaxes);

1) Sourceforge's baselibs 
2) Google Drive's BASEUPLOADS

Hope you'll find them helpful and useful in your learning experience

Regards
« Last Edit: October 13, 2018, 12:19:59 PM by stressful »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #40 on: September 22, 2018, 11:14:17 AM »
== deleted ==
« Last Edit: September 23, 2018, 09:49:23 PM by stressful »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #41 on: September 22, 2018, 11:33:28 AM »
== deleted ==
« Last Edit: September 23, 2018, 09:49:04 PM by stressful »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #42 on: September 23, 2018, 03:59:33 AM »
== deleted ==
« Last Edit: September 23, 2018, 09:48:46 PM by stressful »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: BASELIB: General Purpose Lib for Beginners
« Reply #43 on: September 23, 2018, 04:47:29 PM »
== deleted ==
 
« Last Edit: September 23, 2018, 09:48:25 PM by stressful »

Offline GabrielRavier

  • Jr. Member
  • *
  • Posts: 2
Re: BASELIB: General Purpose Lib for Beginners
« Reply #44 on: October 02, 2018, 07:44:55 AM »
I like optimizing stuff, so I thought I could give some "better" versions of the functions given here :

rndint : https://pastebin.com/5LqfueCk
opsize : https://pastebin.com/hfYpGFq6
iseven : https://pastebin.com/ALDzw7Ey
isodd : https://pastebin.com/ebz2S8Fj
chr_islower : https://pastebin.com/NsSLinge