' asm_sse.pb — SSE floating-point simulation
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL floatA(20) AS DOUBLE
    LOCAL floatB(20) AS DOUBLE
    LOCAL floatResult(20) AS DOUBLE
    LOCAL arraySize AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL sumA AS DOUBLE
    LOCAL sumB AS DOUBLE
    LOCAL sumR AS DOUBLE
    LOCAL dotProduct AS DOUBLE
    LOCAL aVal AS DOUBLE
    LOCAL bVal AS DOUBLE
    LOCAL resVal AS DOUBLE
    LOCAL minVal AS DOUBLE
    LOCAL maxVal AS DOUBLE
    LOCAL avgVal AS DOUBLE
    LOCAL numIter AS LONG
    LOCAL iter AS LONG

    arraySize = 8

    PRINT "=== SSE Floating-Point Simulation ==="
    PRINT "Vector size: " + STR$(arraySize) + " elements"

    FOR i = 0 TO arraySize - 1
        aVal = i * 1.5
        bVal = i * 0.5
        floatA(i) = aVal
        floatB(i) = bVal
    NEXT i

    PRINT "SSE Packed Add (addps):"
    FOR i = 0 TO arraySize - 1
        aVal = floatA(i)
        bVal = floatB(i)
        resVal = aVal + bVal
        floatResult(i) = resVal
        sumR = sumR + resVal
        sumA = sumA + aVal
        sumB = sumB + bVal
        PRINT "  [" + STR$(i) + "] " + STR$(aVal) + " + " + STR$(bVal) + " = " + STR$(resVal)
    NEXT i
    PRINT "  Sum A: " + STR$(sumA)
    PRINT "  Sum B: " + STR$(sumB)
    PRINT "  Sum R: " + STR$(sumR)

    PRINT "SSE Dot Product (dpps):"
    dotProduct = 0
    FOR i = 0 TO arraySize - 1
        aVal = floatA(i)
        bVal = floatB(i)
        dotProduct = dotProduct + aVal * bVal
    NEXT i
    PRINT "  Dot: " + STR$(dotProduct)

    PRINT "SSE Min/Max:"
    minVal = floatResult(0)
    maxVal = floatResult(0)
    FOR i = 1 TO arraySize - 1
        resVal = floatResult(i)
        IF resVal < minVal THEN minVal = resVal
        IF resVal > maxVal THEN maxVal = resVal
    NEXT i
    PRINT "  Min: " + STR$(minVal) + " Max: " + STR$(maxVal)

    avgVal = sumR / arraySize
    PRINT "  Avg: " + STR$(avgVal)
    PRINT "=== End SSE ==="
    FUNCTION = 0
END FUNCTION
