lightning
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Lightning] Working with floating point values and the stack


From: Manuel Mohr
Subject: [Lightning] Working with floating point values and the stack
Date: Thu, 13 Oct 2005 00:51:05 +0200

Hello,

I want to write a function plotter using GNU lightning. Due to its
recursive descent parser it makes heavy use of the push and pop
commands. If I use integers, the program works flawlessly.
However, I want to use floating point arithmetics. The following code
does not print "10" as excepted by me, but it prints "4.4". Pushing and
popping floating point values does not seem to work properly. Moving
the floats to an V?-register before pushing and popping them into
a V?-register didn't work either. What am I doing wrong?

Thanks for help, lightning is really nice so far :)

        Manuel



#include <stdio.h>
#include "lightning.h"

jit_insn code_buffer[1024];

typedef float (*function_t)();

void put() {
        jit_movi_f(JIT_FPR0, 5.6);
        jit_pushr_p(JIT_FPR0);
}

void put2() {
        jit_movi_f(JIT_FPR0, 4.4);
        jit_pushr_p(JIT_FPR0);
}

void add() {
        jit_popr_p(JIT_FPR1);
        jit_popr_p(JIT_FPR2);
        jit_addr_f(JIT_FPR1, JIT_FPR1, JIT_FPR2);
        jit_pushr_p(JIT_FPR1);
}

function_t make_function() {
        function_t fun = (function_t) (jit_set_ip(code_buffer).iptr);
        jit_leaf(1);
        put();
        put2();
        add();

        jit_popr_p(JIT_RET);
        jit_ret();
        jit_flush_code(code_buffer, jit_get_ip().ptr);
        return fun;
}

int main() {
        function_t func = make_function();
        float f = func();
        printf("%f\n", f);
        return 0;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]