flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > [feature request] abs operator |
Author |
|
edfed 20 Jul 2015, 12:00
abs is not an operator.
mathematically, abs(x) = (x²)^1/2 logically, it is just a cmp x,0 jge @f neg x @@: but if it is for the inside of expressions, why not. |
|||
20 Jul 2015, 12:00 |
|
El Tangas 20 Jul 2015, 13:54
Abs, norm, absolute value or whatever you want to call it...
abs x = abs (x) = |x| = sqr(x^2) If it is a function or an operator I think its just semantics. It can be done in an endless number of equivalent ways. and/or/test x,x jns @f neg x @@: And yes, for use in numerical expressions. |
|||
20 Jul 2015, 13:54 |
|
revolution 20 Jul 2015, 15:22
There are other common mathematical operators/functions that are missing also. As examples: sine, cosine, tangent (and their inverses and reciprocals), signum, ceiling, floor, factorial, square root, etc..
Is there really a need? Can your problem be solved another way? Last edited by revolution on 20 Jul 2015, 21:56; edited 1 time in total |
|||
20 Jul 2015, 15:22 |
|
l_inc 20 Jul 2015, 17:10
El Tangas
Code: x xor x shr 64 - x shr 64 _________________ Faith is a superposition of knowledge and fallacy |
|||
20 Jul 2015, 17:10 |
|
El Tangas 20 Jul 2015, 22:31
l_inc wrote: El Tangas I know that trick. Code: cdq xor eax,edx sub eax,edx See? But tnx anyway revolution wrote: There are other common mathematical operators/functions that are missing also. As examples: sine, cosine, tangent (and their inverses and reciprocals), signum, ceiling, floor, factorial, square root, etc.. Of course it can be solved in another way. In fact I already had solved it. I'm not asking for transcendental trig functions, abs is very basic in that list only signum is also basic. Presenting alternative code is like saying "Why do we have 'not x', we can just do '-(x+1)'". Not the point. I was just asking because I imagined it would not be difficult and would generate cleaner and shorter code in some situations. |
|||
20 Jul 2015, 22:31 |
|
l_inc 20 Jul 2015, 22:50
El Tangas
Quote: Presenting alternative code is like saying "Why do we have 'not x', we can just do '-(x+1)'" This wouldn't work for (-1) shl 64 xor (-1) , so I'd better use x xor (-1). But I certainly do agree with your point. _________________ Faith is a superposition of knowledge and fallacy |
|||
20 Jul 2015, 22:50 |
|
revolution 21 Jul 2015, 13:13
l_inc wrote:
|
|||
21 Jul 2015, 13:13 |
|
l_inc 21 Jul 2015, 15:00
revolution
If I was to use this code in VB it wouldn't work at all. As for the arithmetic bit length in fasm the author mentioned he would undertake no big changes anymore. Though I hope this does not include some of the previously planned improvements such as access to the relocation info. _________________ Faith is a superposition of knowledge and fallacy |
|||
21 Jul 2015, 15:00 |
|
El Tangas 22 Jul 2015, 09:55
revolution wrote:
No, this code must always work, because, according to FASM documentation Quote: arithmetical and bit–logical calculations are usually processed as if they operated on infinite precision 2–adic numbers This means any negative number must behave as if it was (1)nnnnn..nnb, in other words, the 'shr' operator in FASM is actually 'sar'. So this code must be equivalent to abs x for any 'arbitrarily large' value of _shift: Code: x xor x shr _shift - x shr _shift |
|||
22 Jul 2015, 09:55 |
|
revolution 22 Jul 2015, 11:35
El Tangas wrote: So this code must be equivalent to abs x for any 'arbitrarily large' value of _shift: |
|||
22 Jul 2015, 11:35 |
|
El Tangas 22 Jul 2015, 12:56
So, there you have it. If there is no absolutely reliable way to get the sign of a numeric value in a way that can be operated upon, I think we need 'abs' and/or 'sgn' to be implemented.
|
|||
22 Jul 2015, 12:56 |
|
cod3b453 25 Jul 2015, 09:55
This could only work if everything is typed otherwise it's ambiguous. This in itself is not a problem but has implications on everything else, in particular previously equivalent statements such as "-1" vs "not 0" vs "$F..F".
As adding this information is going to be long anyway, defining abs/sgn/... via macros seems acceptable, plus it allows for greater controls on edge cases such as -2^(N-1). |
|||
25 Jul 2015, 09:55 |
|
revolution 25 Jul 2015, 16:12
cod3b453 wrote: This could only work if everything is typed otherwise it's ambiguous. This in itself is not a problem but has implications on everything else, in particular previously equivalent statements such as "-1" vs "not 0" vs "$F..F". |
|||
25 Jul 2015, 16:12 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.