aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


client/tests/fpu_stack.c (1926B)


      1 #include "recomp_types.h"
      2 #include <assert.h>
      3 
      4 static void push_preserves_register_bits(void)
      5 {
      6     const uint64_t values[] = {0x8000000000000000ull, 0x7ff8000000001234ull,
      7         0x7ff0000000000000ull, 0xfff0000000000000ull, 1, 2, 3, 4};
      8     const int64_t exact[] = {INT64_MAX, INT64_MIN, 3, 4, 5, 6, 7, 8};
      9     memcpy(g_st, values, sizeof(values));
     10     memcpy(g_st_i64, exact, sizeof(exact));
     11     g_fp_top = 3;
     12 
     13     fp_push_impl(g_st, &g_fp_top, 1.5);
     14 
     15     const uint64_t expected[] = {0x3ff8000000000000ull, 0x8000000000000000ull,
     16         0x7ff8000000001234ull, 0x7ff0000000000000ull, 0xfff0000000000000ull, 1, 2, 3};
     17     const int64_t expected_exact[] = {0, INT64_MAX, INT64_MIN, 3, 4, 5, 6, 7};
     18     assert(!memcmp(g_st, expected, sizeof(expected)));
     19     assert(!memcmp(g_st_i64, expected_exact, sizeof(expected_exact)));
     20     assert(g_fp_top == 4);
     21 }
     22 
     23 static void pop_preserves_register_bits(void)
     24 {
     25     const uint64_t values[] = {0x7ff8000000001234ull, 0x8000000000000000ull,
     26         0x7ff0000000000000ull, 0xfff0000000000000ull, 1, 2, 3, 4};
     27     const int64_t exact[] = {INT64_MAX, INT64_MIN, 3, 4, 5, 6, 7, 8};
     28     memcpy(g_st, values, sizeof(values));
     29     memcpy(g_st_i64, exact, sizeof(exact));
     30     g_fp_top = 3;
     31 
     32     double result = fp_pop_impl(g_st, &g_fp_top);
     33 
     34     const uint64_t expected[] = {0x8000000000000000ull, 0x7ff0000000000000ull,
     35         0xfff0000000000000ull, 1, 2, 3, 4, 0};
     36     const int64_t expected_exact[] = {INT64_MIN, 3, 4, 5, 6, 7, 8, 0};
     37     const uint64_t expected_result = 0x7ff8000000001234ull;
     38     assert(!memcmp(&result, &expected_result, sizeof(result)));
     39     assert(!memcmp(g_st, expected, sizeof(expected)));
     40     assert(!memcmp(g_st_i64, expected_exact, sizeof(expected_exact)));
     41     assert(g_fp_top == 2);
     42 }
     43 
     44 int main(void)
     45 {
     46     push_preserves_register_bits();
     47     pop_preserves_register_bits();
     48     puts("fpu-stack: register bits, exact integer shadows and stack depth passed");
     49 }