Recent posts

#51
OxygenBasic Examples / Re: C++ String example to o2
Last post by Frank Brübach - March 31, 2024, 10:05:44 PM
Topic formating String with c++

Here two more examples I think its Not so hard to adept


  uses windows/msvcrt 'or corewin
  char odata[64]
  sprintf(odata,"%g", double 1/3)
  print odata
  sprintf(odata,"%lli", quad 9/5)
  print odata

'-------------- how to translate these code to o2 ?

' topic string formating c++

'You can use sprintf in combination
'with std::string.c_str().

'------------ 1)
' c_str() returns a const
' char* and works with sprintf:

string a = "test";
string b = "text.txt";
string c = "text1.txt";
char* x = new char[a.length() + b.length() + c.length() + 32];

sprintf(x, "%s %s > %s", a.c_str(), b.c_str(), c.c_str() );
string str = x;
delete[] x;

'------------ 2)
'you can use a pre-allocated
'char array if you know the size:

string a = "test"
string b = "text.txt"
string c = "text1.txt"
char x[256]

sprintf(x, "%s %s > %s", a.c_str(), b.c_str(), c.c_str() );
print x
#52
OxygenBasic Examples / Re: C++ String example to o2
Last post by Charles Pegge - March 31, 2024, 08:36:46 PM
Happy Easter!

I'm not sure what those examples mean but this is how you can use sprintf in o2

'msvcrt val/str/format$ equivalent
'https://www.cplusplus.com/reference/cstdio/printf/
'https://cplusplus.com/reference/cstdio/sprintf/
'nb: msvcrt downgrades extended precision to double.
'uses windows/msvcrt 'or corewin

  uses corewin
  char odata[64]
  sprintf(odata,"%s", "Hello "+"World")
  print odata
  sprintf(odata,"%g", double 1/3)
  print odata
  sprintf(odata,"%lli", quad 9/5)
  print odata
#53
OxygenBasic Examples / C++ String example to o2
Last post by Frank Brübach - March 31, 2024, 06:06:30 PM
Hello Charles,

How can I translate this two Codes to o2?



  uses windows/msvcrt
'  uses corewin

' c# problem
string a= "test"
string b= "text.txt"
string c= "text1.txt"
string.Format (" {0} {1} > {2} ",a,b,c);

' but system passes only *char in system()

' win32 c++
' sprintf() doesnt work acceptable

' std::stringstream object better
' std::stringstream fmt;
' fmt<< a << " " << b << " > " << c;

' c way better
'
' std::Stringstream

' you may use std::stringstream:

#include <iostream>
#include <sstream>
#include <string>

int main() {
    std::string a = "a", b = "b", c = "c";
    // apply formatting
    std::stringstream s;
    s << a << " " << b << " > " << c;
    // assign to std::string
    std::string str = s.str();
    std::cout << str << "\n";
}

' Or (in this case) std::string's very own
' string concatenation capabilities:

#include <iostream>
#include <string>

int main() {
    std::string a = "a", b = "b", c = "c";
    std::string str = a + " " + b + " > " + c;
    std::cout << str << "\n";
}


Nice easter Holidays regards, Frank
#54
Following the tracks of Germany, Netherlands and France

Is this the end of British Farming? Tractors storm Parliament.

PoliticsJOE
28 mar 2024

#55
General Discussion / "Clean" Code, Horrible Perform...
Last post by Charles Pegge - March 30, 2024, 12:57:42 AM
OOP abstractions come at a high cost for both man and machine. Where appropriate use case blocks instead, or better still ,  lookup tables!


Molly Rocket

28 feb 2023

#56
OxygenBasic / Re: Tools for 4 Dimensional Ge...
Last post by Charles Pegge - March 29, 2024, 12:57:24 PM
Note that AVX support is quite patchy. For instance my PC has an AMD Ryzen-3 processor pre 2020, and this does not support AVX.

https://en.wikipedia.org/wiki/Advanced_Vector_Extensions
#57
OxygenBasic / Re: dll for HTTPS that uses th...
Last post by Theo Gottwald - March 29, 2024, 09:11:31 AM
Quote from: Eduardo Jorge on March 27, 2024, 04:21:02 PMTheo, with tls1.2 it works normally on win7, the problem is tls1.3

I seem not to understand the problem.
Why don't you just hop over to Claude3 and ask for a solution?
#58
OxygenBasic / Re: Tools for 4 Dimensional Ge...
Last post by Theo Gottwald - March 28, 2024, 11:12:05 AM
Here's the implementation of the interpolate function in O2 Basic, along with variants in x86 and x64 SIMD assembler:

O2 Basic:

method interpolate(Transform4D other, float t)
    float* a = @f + idx * 4
    float* b = @other.f + other.idx * 4
    float* r = @f + (idx + 25) * 4

    for i = 0 to 24
        r[i] = a[i] + (b[i] - a[i]) * t
    next

    idx += 25 ; Update the matrix index
end method

x86 SIMD Assembler (SSE):

method interpolate_SSE(Transform4D other, float t)
    float* a = @f + idx * 4
    float* b = @other.f + other.idx * 4
    float* r = @f + (idx + 25) * 4

    ; Load the interpolation factor into an SSE register
    movss xmm7, t
    shufps xmm7, xmm7, 0

    ; Perform interpolation using SSE instructions
    mov ecx, 6 ; Loop counter (6 iterations for 24 elements)
    mov esi, a
    mov edi, b
    mov edx, r

    .loop:
        movaps xmm0, [esi]
        movaps xmm1, [edi]
        subps xmm1, xmm0
        mulps xmm1, xmm7
        addps xmm0, xmm1
        movaps [edx], xmm0

        add esi, 16
        add edi, 16
        add edx, 16

        dec ecx
        jnz .loop

    idx += 25 ; Update the matrix index
end method

x64 SIMD Assembler (AVX):

method interpolate_AVX(Transform4D other, float t)
    float* a = @f + idx * 4
    float* b = @other.f + other.idx * 4
    float* r = @f + (idx + 25) * 4

    ; Load the interpolation factor into an AVX register
    vbroadcastss ymm7, t

    ; Perform interpolation using AVX instructions
    mov rcx, 3 ; Loop counter (3 iterations for 24 elements)
    mov rsi, a
    mov rdi, b
    mov rdx, r

    .loop:
        vmovaps ymm0, [rsi]
        vmovaps ymm1, [rdi]
        vsubps ymm1, ymm1, ymm0
        vmulps ymm1, ymm1, ymm7
        vaddps ymm0, ymm0, ymm1
        vmovaps [rdx], ymm0

        add rsi, 32
        add rdi, 32
        add rdx, 32

        dec rcx
        jnz .loop

    idx += 25 ; Update the matrix index
end method

In the O2 Basic implementation, the interpolation is performed element-wise using a loop.

The x86 SIMD assembler variant uses SSE instructions to perform the interpolation. It loads the interpolation factor into an SSE register and uses movaps, subps, mulps, and addps instructions to perform the interpolation on four elements at a time. The loop is unrolled to process 24 elements (6 iterations).

The x64 SIMD assembler variant uses AVX instructions, which can process eight elements at a time. It loads the interpolation factor into an AVX register using vbroadcastss and uses vmovaps, vsubps, vmulps, and vaddps instructions for the interpolation. The loop is unrolled to process 24 elements (3 iterations).

Note that the SIMD assembler code assumes the availability of SSE (x86) or AVX (x64) instructions on the target platform. Make sure to adapt the code to match the specific assembler syntax and conventions of your assembler and platform.


method interpolate(Transform4D other, float t)
    if t < 0.0 or t > 1.0
        print "Error: Interpolation factor t must be between 0 and 1."
        return
    endif

    float* a = @f + idx * 4
    float* b = @other.f + other.idx * 4
    float* r = @f + (idx + 25) * 4

    int i
    for i = 0 to 24
        r[i] = a[i] + (b[i] - a[i]) * t
    next

    idx += 25 ; Update the matrix index
end method

@Charles tell me if you need anything else. As you can see i have mutated to a 4D- ASM Expert "Over night" :-)

#59
OxygenBasic / Re: Tools for 4 Dimensional Ge...
Last post by Charles Pegge - March 28, 2024, 10:03:23 AM
Thanks Theo,

We don't need the full set of 3D matrix operations, but interpolation would be potentially very useful for taking 3D sections of a 4D object. For instance: slicing a 4D hypersphere along the w axis would produce 3D spheres of different sizes.
#60
OxygenBasic / Re: dll for HTTPS that uses th...
Last post by Charles Pegge - March 28, 2024, 09:46:38 AM
QuoteWhy not just use an electric heater?

I have many heaters, but an electric blanket is usually all I need in this climate. A small oil radiator under the table is also quite efficient.


PS: The PowerBasic site is still down:
https://www.powerbasic.com/