interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / src / omega_program_fp32.h

54 lines · 2649 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef OMEGA_PROGRAM_FP32_H
18#define OMEGA_PROGRAM_FP32_H
19/*
20 * FP32 in the program IR (E1 gap row 12; spec/program-fp32.md).
21 *
22 * An FP32 program is an OmegaProgram whose contract types are TYPE_FP32 or u32
23 * (width 32) and whose body steps are, in the FP32 state, ADD SUB MUL DIV with a
24 * binary32 constant (imm = the constant's bits) or OP_CONVERT to u32; in the u32
25 * state the only step is OP_CONVERT (imm = TYPE_FP32). The type check refuses
26 * anything else, so a u32 value never meets an FP32 operation, and two programs
27 * compose only when OutType == InType, so FP32 and u32 programs join only through
28 * a program that converts (omega_program_build_convert).
29 *
30 * FP32 programs have no AArch64 realization (omega_program_realize refuses them
31 * on type); they are evaluated by the qualified numeric library tier
32 * (omega_numeric_cpu_realize: FADD FSUB FMUL DIV, I2FP_U32, F2U) and carry a
33 * program id like every other program.
34 */
35#include "omega_program.h"
36
37/* Build name: in_type -> out_type over steps (<= 64). in_type/out_type are
38 * TYPE_FP32 or TYPE_UNSIGNED_INT, width 32. 0 ok (id computed, not realized),
39 * -1 refused. */
40int omega_program_build_fp32(OmegaProgram *prog, const char *name, TypeTag in_type, TypeTag out_type,
41 const OmegaProgramStep *steps, uint16_t count);
42
43/* The explicit conversion programs: u32 -> FP32 (RNE, I2FP_U32) and FP32 -> u32
44 * (truncate toward zero, saturating, NaN -> 0 as omega_ref_f2u defines). */
45int omega_program_build_convert(OmegaProgram *prog, const char *name, TypeTag from, TypeTag to);
46
47/* Type and body check. 0 ok; -1 refused with the reason in why. */
48int omega_program_fp32_check(const OmegaProgram *prog, char *why, size_t why_len);
49
50/* Evaluate on the library tier. xs and ys are 32-bit patterns (binary32 bits for
51 * an FP32 input or output, a u32 otherwise). 0 ok, -1 refused. */
52int omega_program_fp32_eval(const OmegaProgram *prog, const uint32_t *xs, size_t n, uint32_t *ys);
53
54#endif