mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Add intrinsics.mem_zero
This commit is contained in:
@@ -31,6 +31,13 @@ overflow_add :: proc(lhs, rhs: $T) -> (T, bool) #optional_ok ---
|
|||||||
overflow_sub :: proc(lhs, rhs: $T) -> (T, bool) #optional_ok ---
|
overflow_sub :: proc(lhs, rhs: $T) -> (T, bool) #optional_ok ---
|
||||||
overflow_mul :: proc(lhs, rhs: $T) -> (T, bool) #optional_ok ---
|
overflow_mul :: proc(lhs, rhs: $T) -> (T, bool) #optional_ok ---
|
||||||
|
|
||||||
|
sqrt :: proc(x: $T) -> T where type_is_float(T) ---
|
||||||
|
|
||||||
|
mem_copy :: proc(dst, src: rawptr, len: int) ---
|
||||||
|
mem_copy_non_overlapping :: proc(dst, src: rawptr, len: int) ---
|
||||||
|
mem_zero :: proc(ptr: rawptr, len: int) ---
|
||||||
|
|
||||||
|
|
||||||
fixed_point_mul :: proc(lhs, rhs: $T, #const scale: uint) -> T where type_is_integer(T) ---
|
fixed_point_mul :: proc(lhs, rhs: $T, #const scale: uint) -> T where type_is_integer(T) ---
|
||||||
fixed_point_div :: proc(lhs, rhs: $T, #const scale: uint) -> T where type_is_integer(T) ---
|
fixed_point_div :: proc(lhs, rhs: $T, #const scale: uint) -> T where type_is_integer(T) ---
|
||||||
fixed_point_mul_sat :: proc(lhs, rhs: $T, #const scale: uint) -> T where type_is_integer(T) ---
|
fixed_point_mul_sat :: proc(lhs, rhs: $T, #const scale: uint) -> T where type_is_integer(T) ---
|
||||||
|
|||||||
@@ -2106,6 +2106,47 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case BuiltinProc_mem_zero:
|
||||||
|
{
|
||||||
|
operand->mode = Addressing_NoValue;
|
||||||
|
operand->type = t_invalid;
|
||||||
|
|
||||||
|
Operand ptr = {};
|
||||||
|
Operand len = {};
|
||||||
|
check_expr(c, &ptr, ce->args[0]);
|
||||||
|
check_expr(c, &len, ce->args[1]);
|
||||||
|
if (ptr.mode == Addressing_Invalid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (len.mode == Addressing_Invalid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!is_type_pointer(ptr.type)) {
|
||||||
|
gbString str = type_to_string(ptr.type);
|
||||||
|
error(ptr.expr, "Expected a pointer value for '%.*s', got %s", LIT(builtin_procs[id].name), str);
|
||||||
|
gb_string_free(str);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!is_type_integer(len.type)) {
|
||||||
|
gbString str = type_to_string(len.type);
|
||||||
|
error(len.expr, "Expected an integer value for the number of bytes for '%.*s', got %s", LIT(builtin_procs[id].name), str);
|
||||||
|
gb_string_free(str);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len.mode == Addressing_Constant) {
|
||||||
|
i64 n = exact_value_to_i64(len.value);
|
||||||
|
if (n < 0) {
|
||||||
|
gbString str = expr_to_string(len.expr);
|
||||||
|
error(len.expr, "Expected a non-negative integer value for the number of bytes for '%.*s', got %s", LIT(builtin_procs[id].name), str);
|
||||||
|
gb_string_free(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
case BuiltinProc_atomic_fence:
|
case BuiltinProc_atomic_fence:
|
||||||
case BuiltinProc_atomic_fence_acq:
|
case BuiltinProc_atomic_fence_acq:
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ enum BuiltinProcId {
|
|||||||
|
|
||||||
BuiltinProc_mem_copy,
|
BuiltinProc_mem_copy,
|
||||||
BuiltinProc_mem_copy_non_overlapping,
|
BuiltinProc_mem_copy_non_overlapping,
|
||||||
|
BuiltinProc_mem_zero,
|
||||||
|
|
||||||
BuiltinProc_volatile_store,
|
BuiltinProc_volatile_store,
|
||||||
BuiltinProc_volatile_load,
|
BuiltinProc_volatile_load,
|
||||||
@@ -287,6 +288,7 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
|||||||
|
|
||||||
{STR_LIT("mem_copy"), 3, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
{STR_LIT("mem_copy"), 3, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
||||||
{STR_LIT("mem_copy_non_overlapping"), 3, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
{STR_LIT("mem_copy_non_overlapping"), 3, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
||||||
|
{STR_LIT("mem_zero"), 2, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
||||||
|
|
||||||
{STR_LIT("volatile_store"), 2, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
{STR_LIT("volatile_store"), 2, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
||||||
{STR_LIT("volatile_load"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
{STR_LIT("volatile_load"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||||
|
|||||||
+14
-2
@@ -9478,8 +9478,6 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
|
|||||||
case BuiltinProc_mem_copy:
|
case BuiltinProc_mem_copy:
|
||||||
case BuiltinProc_mem_copy_non_overlapping:
|
case BuiltinProc_mem_copy_non_overlapping:
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
lbValue dst = lb_build_expr(p, ce->args[0]);
|
lbValue dst = lb_build_expr(p, ce->args[0]);
|
||||||
lbValue src = lb_build_expr(p, ce->args[1]);
|
lbValue src = lb_build_expr(p, ce->args[1]);
|
||||||
lbValue len = lb_build_expr(p, ce->args[2]);
|
lbValue len = lb_build_expr(p, ce->args[2]);
|
||||||
@@ -9513,6 +9511,20 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case BuiltinProc_mem_zero:
|
||||||
|
{
|
||||||
|
lbValue ptr = lb_build_expr(p, ce->args[0]);
|
||||||
|
lbValue len = lb_build_expr(p, ce->args[1]);
|
||||||
|
ptr = lb_emit_conv(p, ptr, t_rawptr);
|
||||||
|
len = lb_emit_conv(p, len, t_int);
|
||||||
|
|
||||||
|
LLVMTypeRef type_i8 = LLVMInt8TypeInContext(p->module->ctx);
|
||||||
|
unsigned alignment = 1;
|
||||||
|
LLVMBuildMemSet(p->builder, ptr.value, LLVMConstNull(type_i8), len.value, alignment);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
case BuiltinProc_atomic_fence:
|
case BuiltinProc_atomic_fence:
|
||||||
LLVMBuildFence(p->builder, LLVMAtomicOrderingSequentiallyConsistent, false, "");
|
LLVMBuildFence(p->builder, LLVMAtomicOrderingSequentiallyConsistent, false, "");
|
||||||
|
|||||||
Reference in New Issue
Block a user