From a3223466e80fd1667082287ce7d9fc657ce3faed Mon Sep 17 00:00:00 2001 From: Philip Solobay Date: Fri, 13 Sep 2024 08:31:59 -0500 Subject: [PATCH] Update SIMD instructions for result and make test script friendlier --- compiler/executable-example.scm | 2 +- compiler/test_load_buffer.scm | 59 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 compiler/test_load_buffer.scm diff --git a/compiler/executable-example.scm b/compiler/executable-example.scm index b187931..fa29093 100644 --- a/compiler/executable-example.scm +++ b/compiler/executable-example.scm @@ -84,7 +84,7 @@ (vxorps ymm1 ymm1 ymm1) (vmovaps (rax) ymm2) (vfmadd132ps ymm0 ymm1 ymm2) - (vmovaps ymm0 (rdx)) + (vmovaps ymm2 (rdx)) ; End of function (xor eax eax) diff --git a/compiler/test_load_buffer.scm b/compiler/test_load_buffer.scm new file mode 100644 index 0000000..16b7224 --- /dev/null +++ b/compiler/test_load_buffer.scm @@ -0,0 +1,59 @@ +(use-modules (system foreign)) + +(define-module (buffer test) + #:use-module (system foreign) + #:export (get-buffer1 get-result)) + +;; Load the shared library and initialize +(load-extension "./liboutput.so" "perform_operations") + +(define lib (dynamic-link "./liboutput.so")) +(define result-ptr (dynamic-pointer "result" lib)) +(define buffer1-ptr (dynamic-pointer "buffer1" lib)) +(define buffer2-ptr (dynamic-pointer "buffer2" lib)) +(define multiplier-ptr (dynamic-pointer "multiplier" lib)) + +(define (get-result) + (pointer->bytevector result-ptr 32)) ; Assuming result is a 32-byte vector + +(define (get-buffer1) + (pointer->bytevector buffer1-ptr 32)) ; Assuming result is a 32-byte vector + +(define (get-buffer2) + (pointer->bytevector buffer2-ptr 32)) ; Assuming result is a 32-byte vector + +(define (get-multiplier) + (pointer->bytevector multiplier-ptr 32)) ; Assuming result is a 32-byte vector + +(define perform-operations + (pointer->procedure void + (dynamic-func "perform_operations" lib) + '())) + + +;; Function to convert a bytevector into a list of floats +(define (bytevector-to-floats bv) + (let ((floats '())) + (do ((i 0 (+ i 4))) + ((>= i (bytevector-length bv)) (reverse floats)) + ;; Read 4 bytes from the bytevector and convert to float + (let* ((b0 (bytevector-u8-ref bv i)) + (b1 (bytevector-u8-ref bv (+ i 1))) + (b2 (bytevector-u8-ref bv (+ i 2))) + (b3 (bytevector-u8-ref bv (+ i 3))) + ;; Combine bytes into a 32-bit float (little-endian) + (int32 (logior (ash b3 24) + (ash b2 16) + (ash b1 8) + b0)) + (float (bitwise-float32->number int32))) + (set! floats (cons float floats)))))) + +;; Usage example +(display "buffer1 as floats: ") +(display (bytevector-to-floats (get-buffer1))) +(newline) + +(display "result as floats: ") +(display (bytevector-to-floats (get-result))) +(newline) -- 2.39.5